DCA September 2021: Check number is "UNO" or "NOT UNO"
Following code is to check if a given positive integer input by user is UNO number or NOT UNO
For e.g. if user input is 1234 then here the sum of digits if the given number is 1+2+3+4 = 10 and then again if we sum the digits of resulting number i.e. 10 is 1+0 = 1 hence if this kind of sum of digits of a number is 1 then the number is said UNO else NOT UNO
NOT UNO e.g. 234 here sum of digits is 2+3+4 = 9, this is not equal to 1 hence it is said NOT UNO
Python Program:
num = int(input()) #takes user input
def check_uno(num):
sum_d = 0
k = 0
while num > 0:
k = num % 10
sum_d = sum_d + k
num = num // 10
if sum_d == 1 or sum_d == 10:
print("UNO")
elif (sum_d > 1 and sum_d < 10):
print("NOT UNO")
elif sum_d > 11:
b = check_uno(sum_d)
check_uno(num)
#Output:
Input = 1234 Output = UNO
Input = 12345 Output = NOT UNOInput = 345345 Output = NOT UNO
Comments
Post a Comment