Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def menu():
- print( '(1) EXPANDED SUM\n'
- '(2) REVERSE EXPANDED SUM\n'
- '(3) REVERSE INTERGER\n'
- '(4) PRODUCT TABLE\n'
- '(5) EXIT\n')
- def poscheck():
- while True:
- global n
- n = input('Please enter a positive interger: ')
- v = int(n)
- if v > 0:
- return
- else:
- continue
- return
- def printSum(n, reverse):
- sum = 0
- running = ''
- for num in range(n) :
- num += 1
- sum += num
- if (reverse == True):
- running = str(num) + running
- else:
- running += str(num)
- if (n == num):
- running += '='+ str(sum)
- else:
- if (reverse == True):
- running = '+'+ running
- else:
- running += '+'
- print(running)
- def reverseint(n):
- print(int(str(n)[::-1]))
- def printProductTable(n):
- for row in range(1,n+1):
- print(*("{:3}".format(row*col) for col in range(1, n+1)))
- menu()
- x = input('Please choose option 1, 2, 3, 4, or 5: ')
- x = int(x)
- if x == 5:
- quit()
- poscheck()
- if (x == 1):
- reverse = False
- n = int(n)
- printSum(n, reverse)
- if (x == 2):
- reverse = True
- n = int(n)
- printSum(n, reverse)
- if (x == 3):
- reverseint(n)
- if (x == 4):
- printProductTable(n)
- while True:
- menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement