here is my code for a calculator:
def menu():
    print "Welcome to calculator.py"    print "your options are:"    print " "  
  print "1) Addition"    print "2) Subtraction"    print "3) Multiplication"    
print "4) Division"    print "5) Quit calculator.py"    print " "    return 
input ("Choose your option: ")    
def add(a,b):    print a, "+", b, "=", a + b    
def sub(a,b):    print b, "-", a, "=", b - a    
def mul(a,b):    print a, "*", b, "=", a * b    
def div(a,b):    print a, "/", b, "=", a / b    def main():    loop = 1    
choice = 0    while loop == 1:        choice = menu()        if choice == 1:    
        add(input("Add this: "),input("to this: "))        elif choice == 2:    
        sub(input("Subtract this: "),input("from this: "))        elif choice 
== 3:            mul(input("Multiply this: "),input("by this: "))        elif 
choice == 4:            div(input("Divide this: "),input("by this: "))        
elif choice == 5:            loop = 0
    print "Thank you for using calculator.py!"


main()

Few questions:
why do i have to press enter for it to initialisewhy does it print the stuff in 
menu() again after doing the equationi am trying to understand classes if 
anyone has time to make all these functions go into a class calculator and have 
it still work and send me the code so i can have an example to refer to that 
would be great                                     
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to