# [Tutor] (no subject)

Wei Juen Lo weij383 at hotmail.com
Sat Apr 28 15:08:37 CEST 2012

```here is my code for a calculator:
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120428/9f400d8c/attachment.html>
```