Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. x = input('Enter x: ')
  2. y = input('Enter y: ')
  3. x = int(x)
  4. y = int(y)
  5. count = 0
  6. last = 0
  7. a = x
  8. b = y
  9. while x > 0 or y > 0:
  10. if x % 10 + y % 10 + last > 9:
  11. count = count + 1
  12. last = 1
  13. else:
  14. last = 0
  15. x = x // 10
  16. y = y // 10
  17.  
  18. if count == 0:
  19. print(a,' + ',b,' has no carries.')
  20. elif count == 1:
  21. print(a,' + ',b,' has one carry.')
  22. else:
  23. print(a,' + ',b,' has ',count,' carries.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement