Pseudocodes On Number DataTypes
Pseudocodes On Number DataTypes
Pseudocodes On Number DataTypes
py 05/04/2023 09:49 PM
a=10
b=20
print('addition = ', a+b)
print(f'subtraction = ' ,a-b)
num=20
if(num<0):
num=num*-1
print(num)
num1=20
num2=30
if(num1==num2):
print('numbers are equal')
else:
print('numbers are not equal')
n=20
if(n>=-9 & n<=9):
print(n,'is a digit')
else:
print(n,'is two digit')
5.take input from user and check its 2 digit or single digit number
Page 1 of 22
numbers.py 05/04/2023 09:49 PM
8.Read month number from user & print Corresponding How many Days in that month
Page 2 of 22
numbers.py 05/04/2023 09:49 PM
m = int(input('m : '))
b = int(input('b : '))
per = ((p + c + m + b) / 4)
n=10
i=1
while(i<=n):
print(i)
i=i+1
for i in range(5):
print(i,end=" ")
12.print from n to 1
n=10
for i in range(n,0,-1):
Page 3 of 22
numbers.py 05/04/2023 09:49 PM
i =10
while (i >= 1):
print(i, end=' ')
i = i - 1
13.multiplication table
num=12
for i in range(1, 11):
print(num, 'x', i, '=', num*i)
for i in range(1,20):
if i%2==0:
print(i,end=" ")
15.sum of even
result = 0
for x in range(1, 10):
if (x % 2 == 0):
result = result + x
Page 4 of 22
numbers.py 05/04/2023 09:49 PM
output = addNumbers(12,9)
print(output)
a,b = SwapTwoNumbers(17,24)
print("After Swap: ",a,b)
19.Read amount from user & print it in the Indian Currency Dimenssion
amt=int(input("Enter the numerical amount : "))
print("2000rs --> ", int(amt/2000))
amt=amt%2000
print("500rs --> ", int(amt/500) )
amt=amt%500
print("200rs --> ", int(amt/200) )
amt=amt%200
print("100rs --> ", int(amt/100) )
amt=amt%100
print("50rs --> ", int(amt/50) )
amt=amt%50
print("20rs --> ", int(amt/20) )
amt=amt%20
print("10rs --> ", int(amt/10) )
Page 5 of 22
numbers.py 05/04/2023 09:49 PM
amt=amt%10
print("5rs --> ", int(amt/5) )
amt=amt%5
print("2rs --> ", int(amt/2) )
amt=amt%2
print("1rs --> ", int(amt/1) )
amt=amt%1
20.factorial
def factorial(n):
fact = 1
while(n!=0):
fact = fact*n
n = n-1
print("The factorial is",fact)
sum = 0
while (n != 0):
sum = sum + (n % 10)
n = n//10
return sum
n = 12345
print(getSum(n))
Page 6 of 22
numbers.py 05/04/2023 09:49 PM
n=n//10
if(temp==rev):
print("The number is a palindrome!")
else:
print("The number isn't a palindrome!")
even_count, odd_count = 0, 0
24.Python Program to check whether the given input is alphabet, number or special character
if((ch >= 'a' and ch <= 'z') or (ch >= 'A' and ch <= 'Z')):
print("The Given Character ", ch, "is an Alphabet")
elif(ch >= '0' and ch <= '9'):
print("The Given Character ", ch, "is a Digit")
else:
print("The Given Character ", ch, "is a Special Character")
Page 7 of 22
numbers.py 05/04/2023 09:49 PM
print("Vowel")
else:
print("Consonant")
gvn_num = 111000101
ones_cnt = 0
zeros_cnt = 0
while gvn_num:
remindr = gvn_num % 10 # Calculate the value of the given number modulus 10 (which gives the last digit of the given Number).
gvn_num = int(gvn_num/10) # Calculate the value of the given number divided by 10 (which removes the last digit of the given n
if remindr == 1:
ones_cnt = ones_cnt+1
if remindr == 0:
zeros_cnt = zeros_cnt+1
output:
The Count of 0's in a given number = 4
The Count of 1's in a given number = 5
Page 8 of 22
numbers.py 05/04/2023 09:49 PM
* n=5
sum=0
for i in range(1,n+1):
sum=sum+i
print(sum)
* while(n!= 0):
sum = sum+n
n = n-1
print("Sum of natural numbers", "=", sum)
number = 8
m = 1
while(m <= 10):
print(number, "*", m, "=", number*m)
m = m+1
Page 9 of 22
numbers.py 05/04/2023 09:49 PM
number = 5
temp = False
# We will check if the number is greater than 1 or not
# since prime numbers starts from 2
if number > 1:
output:
1 ! = 1
Page 10 of 22
numbers.py 05/04/2023 09:49 PM
2 ! = 2
3 ! = 6
4 ! = 24
5 ! = 120
6 ! = 720
7 ! = 5040
* given_number = 27482
digits_count = 0
while (given_number > 0):
given_number = given_number//10
digits_count = digits_count + 1
print("The total digits present in the given number=", digits_count)
* given_number = 27482
print("The total digits present in the given number=", len(str(given_number)))
gvn_num = 154
str_numbr = str(gvn_num)
lst = list(str_numbr)
maxim_digit = max(lst)
print("The maximum digit in given number {", gvn_num, "} = ", maxim_digit)
Page 11 of 22
numbers.py 05/04/2023 09:49 PM
38.Find Those Numbers which are Divisible by 7 and Multiple of 5 in a Given Range of Numbers
lowerlimit = 10
upperlimit = 200
print("The number which is divisible by 7 and multiple of 5 :")
for numb in range(lowerlimit, upperlimit+1):
if(numb % 7 == 0 and numb % 5 == 0):
print('Number =',numb)
output:
The number which is divisible by 7 and multiple of 5 :
Number = 35
Number = 70
Number = 105
Number = 140
Number = 175
Page 12 of 22
numbers.py 05/04/2023 09:49 PM
40.Accept Three Digits and Print all Possible Combinations from the Digits
firstDigit = 1
secondDigit = 9
thirdDigit = 2
digitsList = []
digitsList.append(firstDigit)
digitsList.append(secondDigit)
digitsList.append(thirdDigit)
# Using nested loops
for i in range(3):
for j in range(3):
for k in range(3):
if(i != j & j != k & k != i):
print(digitsList[i], digitsList[j], digitsList[k])
Output:
1 9 2
1 2 9
9 1 2
9 2 1
2 1 9
2 9 1
41.Find Even Digits Sum and Odd Digits Sum Divisible by 4 and 3 Respectively
numb = 123452
stringnum = str(numb)
digtslst = list(map(int, stringnum)) # Create a list of digits say "digtslst" using map(),list(),int functions.
evn_sum = 0
od_sum = 0
Page 13 of 22
numbers.py 05/04/2023 09:49 PM
else:
od_sum += digtslst[itr]
Output: yes, the even digits sum and odd digits sum of a given number{ 123452 } is divisible by 4 and 3 respectively.
42.Count the Number of Odd and Even Digits of a Number at Even and Odd places
numb = 1787725620
stringnum = str(numb)
evn_sum = 0
od_sum = 0
print("The sum of all digits at even places in a given number{", numb, "} =", evn_sum)
print("The sum of all digits at odd places in a given number {", numb, "} =", od_sum)
Output:
The sum of all digits at even places in a given number{ 1787725620 } = 23
The sum of all digits at odd places in a given number { 1787725620 } = 22
numb = 1237891
stringnum = str(numb)
Page 14 of 22
numbers.py 05/04/2023 09:49 PM
evn_count = 0
od_count = 0
print("The count of even digits in a given number{", numb, "} =", evn_count)
print("The count of odd digits in a given number{", numb, "} =", od_count)
Output:
The count of even digits in a given number{ 1237891 } = 2
The count of odd digits in a given number{ 1237891 } = 5
gvn_lowrlmt = 50
gvn_upprlmt = 130
print("The palindrome numbers between", gvn_lowrlmt, "and", gvn_upprlmt, "are:")
reverse_number = 0
if(duplicate_num == reverse_number):
print(duplicate_num, end=" ")
Output: The palindrome numbers between 50 and 130 are: 55 66 77 88 99 101 111 121
Page 15 of 22
numbers.py 05/04/2023 09:49 PM
gvn_numb = 6
resltsum = 0
k = 9
for itr in range(1, gvn_numb+1):
resltsum += k
k = (k*10)+9
print("The total sum of the series till the given number {", gvn_numb, "} = ", resltsum)
Output: The total sum of the series till the given number { 6 } = 1111104
print("The above series till the given number{", gvn_numb, "} is :")
while itr <= gvn_numb:
print(itr, end=" ")
itr *= 2
Output:
Enter some Random Number = 50
The above series till the given number{ 50 } is :1 2 4 8 16 32
gvn_numb = 5
print("The above series till the given number{", gvn_numb, "} is :")
Page 16 of 22
numbers.py 05/04/2023 09:49 PM
print(end=" ")
Output: The above series till the given number{ 5 } is : 1 22 333 4444 55555
48.Disarium Number
num = 135
ans = 0
digits = len(str(num))
dup_number = num
while (dup_number != 0):
remainder = dup_number % 10
ans = ans + remainder**digits
digits = digits - 1
dup_number = dup_number//10
if(num == ans):
print(num, "is disarium number")
else:
print(num, "is not disarium number")
num = 153
ans = 0
digits = len(str(num))
dup_number = num
while (dup_number != 0):
remainder = dup_number % 10
ans = ans + remainder**digits
dup_number = dup_number//10
if(num == ans):
print(num, "is Armstrong number")
else:
Page 17 of 22
numbers.py 05/04/2023 09:49 PM
def checkPerfectNumb(givenNumb):
totalSum = 1
if(totalSum == givenNumb):
return True
return False
given_numb = 6
if(checkPerfectNumb(given_numb)):
print("The given number", given_numb, "is perfect number")
else:
print("The given number", given_numb, "is not a perfect number")
def checkPerfectNumbr(givenNumb):
totalSum = 1
Page 18 of 22
numbers.py 05/04/2023 09:49 PM
totalSum += i
if(totalSum == givenNumb):
return True
return False
lowlimrange = 1
upplimrange = 1000
print('The Perfect numbers in the given range', lowlimrange, 'and', upplimrange, 'are:')
Output: The Perfect numbers in the given range 1 and 1000 are: 1 6 28 496
def checkStrongNumb(givenNumb):
totalSum = 0
tempNum = givenNumb
while(s <= remainder): # calculating the factorial of the digit(extracted by remainder variable)
factNum = factNum * s
s = s + 1
if(totalSum == tempNum):
return True
Page 19 of 22
numbers.py 05/04/2023 09:49 PM
return False
given_numb = 145
if(checkStrongNumb(given_numb)):
print("The given number", given_numb, "is strong number")
else:
print("The given number", given_numb, "is not a strong number")
def digitSquareSum(resltnumber):
strnumbe = str(resltnumber)
numbrlistdigits = list(map(int, strnumbe))
sumsquaredigits = 0
for digitvalu in numbrlistdigits:
sumsquaredigits = sumsquaredigits+(digitvalu**2)
return sumsquaredigits
numbr = 100
while(reslt != 1 and reslt != 4):
reslt = digitSquareSum(reslt)
if(reslt == 1):
print('The given number [', numbr, '] is a happy number')
else:
print('The given number [', numbr, '] is not a happy number')
Page 20 of 22
numbers.py 05/04/2023 09:49 PM
def digitSquareSum(resltnumber):
strnumbe = str(resltnumber)
numbrlistdigits = list(map(int, strnumbe))
sumsquaredigits = 0
return sumsquaredigits
def checkhapppynumb(numb):
rest = numb
if(rest == 1):
return True
else:
return False
lowlimrange = 19
upplimrange = 145
print('The happy numbers in the given range', lowlimrange, 'and', upplimrange, 'are:')
Output:
The happy numbers in the given range 19 and 145 are:
19 23 28 31 32 44 49 68 70 79 82 86 91 94 97 100 103 109 129 130 133 139
Page 21 of 22
numbers.py 05/04/2023 09:49 PM
givenNumbr = 95
print('The prime numbers from 2 to upper limit [', givenNumbr, '] :')
Output:
The prime numbers from 2 to upper limit [ 95 ] :
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89
Page 22 of 22