Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- def showMenu(): # Function that display the menu
- print('1. Addition')
- print('2. Subtraction')
- print('3. Multiplication')
- print('4. Division')
- print('5. Exit\n')
- def myChoice(): # Take your choice in input
- c = input('')
- return int(c)
- def select(c): # This function prints the choice you entered
- if c == 1:
- print('\nAddition')
- elif c == 2:
- print('\nSubtraction')
- elif c == 3:
- print('\nMultiplication')
- elif c == 4:
- print('\nDivision')
- else:
- exit(1) # Forces the exit if we enter the value 5
- def calc(a, b, c): # Returns the result of the caclculations
- if c == 1:
- return a+b
- elif c == 2:
- return a-b
- elif c == 3:
- return a*b
- elif c == 4:
- return a/b
- def signFunc(c): # Change the sign depending on your choice
- if c == 1:
- return' + '
- elif c == 2:
- return ' - '
- elif c == 3:
- return ' * '
- elif c == 4:
- return ' / '
- mainLoop = 1;
- while mainLoop : # Infinite loop
- sign = ' + ';
- showMenu()
- c = myChoice()
- select(c)
- sign = signFunc(c)
- print('Enter the first number: ')
- entry1 = input(''); # First entry
- print('Enter the second number: ')
- entry2 = input(''); # Second entry
- entry1 = float(entry1) # Convert our entries into floats
- entry2 = float(entry2)
- result = calc(entry1, entry2, c)
- print('\n' + str(entry1) + sign + str(entry2) + ' = ' + str(result) + '\n\n')
- os.system('Pause')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement