Hey all,
 
Thought I'd try a mini-calc. Here's the code:
 
# This is a small calculator.
print "Mini Calculator"
print "By Nathan Pinno"
print
print "CALCULATE MENU"
print "1) Add"
print "2) Subraction"
print "3) Multiplication"
print "4) Division w/o remainder"
print "5) Division with remaider"
print "6) Exponation"
print "7) Square roots"
print "8) Exit"
cal_opt = int(raw_input("What option would you like: "))
if cal_opt == "1":
    X = input("First number:" )
    Y = input("Second number:" )
    print X, "+", Y, "= ",X + Y
    cal_opt = int(raw_input("Option: "))
elif cal_opt == "2":
    X = input("First number:" )
    Y = input("Second number:" )
    print X, "-", Y, "= ",X - Y
    cal_opt = int(raw_input("Option: "))
elif cal_opt == "3":
    X = input("First number:" )
    Y = input("Second number:" )
    print X, "*", Y, "= ",X * Y
    cal_opt = int(raw_input("Option: "))
elif cal_opt == "4":
    X = input("First number:" )
    Y = input("Second number:" )
    if Y == 0:
        print "Division by zero ot allowed!"
        Y = input("Second number:" )
    else:
        print X, "/", Y, "= ",X / Y
        cal_opt = int(raw_input("Option: "))
elif cal_opt == "5":
    X = input("First number:" )
    Y = input("Second number:" )
    if Y == 0:
        print "Division by zero ot allowed!"
        Y = input("Second number:" )
    else:
        print X, "/", Y, "= ",X / Y," R ", X % Y
        cal_opt = int(raw_input("Option: "))
elif cal_opt == "6":
    X = input("First number:" )
    Y = input("Power:" )
    print X, "**", Y, "= ",X**Y
    cal_opt = int(raw_input("Option: "))
elif cal_opt == "7":
    X = input("Number to find the square root of:" )
    print "The square root of", X, " = ",X**0.5
    cal_opt = int(raw_input("Option: "))
elif cal_opt == "8":
    print "Goodbye!"
else:
    print "That's not an option. Try again."
    cal_opt = int(raw_input("Option: "))
Here is the screen output:
 
Mini Calculator
By Nathan Pinno
 
CALCULATE MENU
1) Add
2) Subraction
3) Multiplication
4) Division w/o remainder
5) Division with remaider
6) Exponation
7) Square roots
8) Exit
What option would you like: 7
That's not an option. Try again.
Option: 3
3*4
12
>>>
 
Why does it run this way instead of going to the proper equation?
 
Appreciating the help so far,
Nathan Pinno

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to