Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Problem 5. Write a program that inputs integers until it gets a zero and prints the one with the maximum sum of its odd digits. If there is more than one such number, print the first one.
- x=int(input("Enter an integer: "))
- max_sum=0
- number=0
- while x:
- temp=x
- temp=abs(temp)
- sum=0
- while temp:
- last_dig=temp%10
- temp=temp//10
- if last_dig%2==1:
- sum=sum+last_dig
- if sum>max_sum:
- max_sum=sum
- number=x
- x=int(input("Enter an integer: "))
- print("The number with the maximum sum of odd digits is ", number, "and the value of the sum is ", max_sum)
Add Comment
Please, Sign In to add comment