Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. '''
  2. Created on 20 Feb 2020
  3.  
  4. @author: LOSS
  5. '''
  6.  
  7. def print_sum(num1,num2):
  8. finalsum = 0
  9.  
  10. if isinstance(num1,int) or isinstance(num1,float):
  11. if isinstance(num2,int) or isinstance(num2,float):
  12.  
  13. #Move values one at the time from smaller to larger number
  14. # until smaller is zero
  15. if num1 > num2:
  16. finalsum = num1
  17.  
  18. while num2 != 0:
  19. if num2 < 0:
  20. finalsum -=1
  21. num2 +=1
  22. else:
  23. finalsum += 1
  24. num2 -= 1
  25. elif num2 > num1:
  26. finalsum = num2
  27.  
  28. while num1 != 0:
  29. if num1 > 0:
  30. finalsum += 1
  31. num1 -= 1
  32. else:
  33. finalsum -= 1
  34. num1 +=1
  35.  
  36.  
  37. return finalsum
  38.  
  39. def main():
  40. num1 = 50
  41. num2 = -20
  42.  
  43. print(print_sum(num1,num2))
  44.  
  45.  
  46. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement