Guest User

Untitled

a guest
Feb 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. ##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.
  2.  
  3. x=int(input("Enter an integer: "))
  4. max_sum=0
  5. number=0
  6. while x:
  7. temp=x
  8. temp=abs(temp)
  9. sum=0
  10. while temp:
  11. last_dig=temp%10
  12. temp=temp//10
  13. if last_dig%2==1:
  14. sum=sum+last_dig
  15. if sum>max_sum:
  16. max_sum=sum
  17. number=x
  18. x=int(input("Enter an integer: "))
  19. 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