Advertisement
Guest User

Untitled

a guest
Dec 10th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. def menu():
  2. print( '(1) EXPANDED SUM\n'
  3. '(2) REVERSE EXPANDED SUM\n'
  4. '(3) REVERSE INTERGER\n'
  5. '(4) PRODUCT TABLE\n'
  6. '(5) EXIT\n')
  7.  
  8. def poscheck():
  9. while True:
  10. global n
  11. n = input('Please enter a positive interger: ')
  12. v = int(n)
  13. if v > 0:
  14. return
  15. else:
  16. continue
  17. return
  18.  
  19. def printSum(n, reverse):
  20. sum = 0
  21. running = ''
  22. for num in range(n) :
  23. num += 1
  24. sum += num
  25. if (reverse == True):
  26. running = str(num) + running
  27. else:
  28. running += str(num)
  29. if (n == num):
  30. running += '='+ str(sum)
  31. else:
  32. if (reverse == True):
  33. running = '+'+ running
  34. else:
  35. running += '+'
  36. print(running)
  37.  
  38. def reverseint(n):
  39. print(int(str(n)[::-1]))
  40.  
  41. def printProductTable(n):
  42. for row in range(1,n+1):
  43. print(*("{:3}".format(row*col) for col in range(1, n+1)))
  44.  
  45. menu()
  46.  
  47. x = input('Please choose option 1, 2, 3, 4, or 5: ')
  48.  
  49. x = int(x)
  50.  
  51. if x == 5:
  52. quit()
  53.  
  54. poscheck()
  55.  
  56. if (x == 1):
  57. reverse = False
  58. n = int(n)
  59. printSum(n, reverse)
  60.  
  61. if (x == 2):
  62. reverse = True
  63. n = int(n)
  64. printSum(n, reverse)
  65.  
  66. if (x == 3):
  67. reverseint(n)
  68.  
  69. if (x == 4):
  70. printProductTable(n)
  71.  
  72. while True:
  73. menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement