design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum of digits 9 + 4 + 3 + 1 + 1, which is 18. The program should end after displaying the sum.You should only use the declared variables sum of digits and number. You are not allowed to declare any other variables (only two variables are allowed). Hint: You should use a loop and take advantage of integer division by 10 and modulus of 10 (this is in python)
Python Code for this problem is :
print("Enter a positive number :
")
num=int(input())
while(num<=0):
print("Enter a positive number : ")
num=int(input())
sum=0
while(num>0):
sum=sum+num%10
num=int(num/10)
print("Sum of digits is : ",sum)
Get Answers For Free
Most questions answered within 1 hours.