Python Forum
Need suggested alterations (6 function calculator)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need suggested alterations (6 function calculator)
#8
(Nov-08-2016, 11:13 PM)EwH006 Wrote: Also what is the keyword for terminating a whole program, or is there one. Is this where loops come in?
Yes to run as shown under you need a running loop.
It's hard if you have to much in global space,keep it in functions.
So in this example there is function menu(),that always loop until Quit.
You always fall back into this function for new choice.
I just use one add() function to show the point.
def add(user_input):
   integer1, integer2 = user_input()
   print('{} + {} = {}'.format(integer1, integer2, integer1+integer2))

def user_input():
   integer1 = int(input("Enter an int between 1 $ 12: "))
   integer2 = int(input("Enter an int between 1 $ 12: "))
   return integer1, integer2

def show_options():
   print("1. (-A-) Addition Operation")
   print("2. (-S-) Subtraction Operation")
   print('(Q) Quit\n')

def menu():
   show_options()
   while True:
       choice = input('Enter your choice: ').lower()
       if choice == '1':
           add(user_input)
       elif choice == '2':
           pass
       elif choice == 'q':
           return False
       else:
           print('Not a correct choice: {}'.format(choice))

if __name__ == '__main__':
   menu()
Reply


Messages In This Thread
RE: Need suggested alterations (6 function calculator) - by snippsat - Nov-09-2016, 06:30 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020