[Tutor] Looks like Giant Calc is a bust.

Nathan Pinno falcon3166 at hotmail.com
Sun Jul 10 05:16:50 CEST 2005


Hey all,

The Giant Calculator runs now, just not as I want it to. I can't seem to get it past the main menu. Here is the code:

# This program is designed as a big calculator with functions.

# This first bunch of code is for the various menus. I decided to divide the calculations into seperate sub-menus,
#so that the main menus would not be that long.
option = 0
a = 0
b = 0
temp_option = 0
formula_option = 0

def main_menu():
   print "OPTIONS MENU"
   print "1) Calculate"
   print "2) Shapes"
   print "3) Temperature"
   print "4) Formulas"
   print "5) Quit"
   option = input("What option would you like:" ) 

def cal_menu():
    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) Back to the previous menu."
    a = input("What option would you like:" )

def shape_menu():
    print "SHAPES MENU"
    print "Important: The figure that is used for pi is 3.14."
    print "1) Squares"
    print "2) Circles"
    print "3) Rectangles"
    print "4) Triangles"
    print "5) Cones"
    print "6) Cylinders"
    print "7) Semicircles"
    print "8) Main menu"
    b = input("What option would you like?" )

def temp_menu():
    print "1) Convert degrees Kevins to degrees Celsius"
    print "2) Contvert Fahrenheit to Celsius"
    print "3) Convert Celsius to Fahrenheit"
    print "4) Convert Celsius to Kelvins"
    print "5) Convert Kelvins to Fahrenheit"
    print "6) Convert Fahrenheit to Kelvins"
    print "7) Main Menu"
    temp_option = input("Choice: ")

def formula_menu():
    print "1) Interest"
    print "2) Distance"
    print "3) Uniform motion"
    print "4) Momentum"
    print "5) Uniformly accelerated motion"
    print "6) Falling bodies"
    print "7) Weight"
    print "8) Main menu"
    fourmula_option = input("Choice: ")

#Code for main part of program.
print "The Giant Calculator"
print
print "Copyright 2005 Written and debugged by Nathan Pinno"
print 
print main_menu()
if option == 1:
    print cal_menu()
    if a == 1:
        X = input("First number:" )
        Y = input("Second number:" )
        print X, "+", Y, "= ",X + Y
        print cal_menu()
    elif a == 2:
        X = input("First number:" )
        Y = input("Second number:" )
        print X, "-", Y, "= ",X - Y
        print cal_menu()
    elif a == 3:
        X = input("First number:" )
        Y = input("Second number:" )
        print X, "*", Y, "= ",X * Y
        print cal_menu()
    elif a == 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
            print cal_menu()
    elif a == 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
            print cal_menu()
    elif a == 6:
        X = input("First number:" )
        Y = input("Power:" )
        print X, "**", Y, "= ",X**Y
        print cal_menu()
    elif a == 7:
        X = input("Number to be squared:" )
        print "The square root of", X, " = ",X**0.5
        print cal_menu()
    elif a == 8:
        print main_menu()
    else:
        print "That's not an option. Try again."
        a = input("What option would you like:" )
elif option == 2:
    print shape_menu()
    if b == 1:
        print "1) Circumference"
        print "2) Area"
        print "3) Shapes Menu"
        op = input("Choice: ")
        if op == 1:
            side = input("Side: ")
            print "Circumference = ",4*side
            print shape_menu()
        elif op == 2:
            side = input("Side: ")
            print "Area = ",side**2
            print shape_menu()
        elif op == 3:
            print shape_menu()
        else:
            print "That's not an option."
            op = input("Choice: ")
    elif b == 2:
        print "1) Circumference"
        print "2) Area"
        print "3) Shapes Menu"
        d = input("Choice: ")
        if d == 1:
            diameter = input("Diameter: ")
            print "The circumference of the circle is ",diameter*3.14
            print shape_menu()
        elif d == 2:
            radius = input("Radius: ")
            print "The area of the circle is ",3.14*(radius**2)
            print shape_menu()
        elif d == 3:
            print shape_menu()
        else:
            print "That's not an option."
            d = input("Choice: ")
    elif b == 3:
        print "1) Area"
        print "2) Perimeter"
        print "3) Main menu"
        g = input("Choice: ")
        if g == 1:
            base = input("Base: ")
            altitude = input("Altitude: ")
            print "The area of the rectangle is: ",base*altitude
            print shape_menu()
        elif g == 2:
            base = input("Base: ")
            altitude = input("Altiutude: ")
            print "The perimeter of the rectangle is: ",(2*base)+(2*altitude)
            print shape_menu()
        elif g == 3:
           print shape_menu()
        else:
           print "That's not an option."
           g = input("Choice: ")
    elif b == 4:
        print "1) Right Triangles - Pygathorean Theorum"
        print "2) Perimeter"
        print "3) Area"
        print "4) Shapes Menu"
        e = input("Choice: ")
        if e == 1:
            sidea = input("Side A: ")
            sideb = input("side B: ")
            print "The hypotenuse's length is: ",((sidea**2)+(sideb**2))**0.5
            print shape_menu()
        elif e == 2:
            sidea = input("Side A: ")
            sideb = input("Side B: ")
            sidec = input("Side C: ")
            print "The Perimeter of the triangle is: ",sidea+sideb+sidec
            print shape_menu()
        elif e == 3:
            base = input("Base: ")
            height = input("Height: ")
            print "The area of the triangle is: ",1/2*base*height
            print shape_menu()
        elif e == 4:
            print shape_menu()
        else:
            print "That's not an option! Try again."
            e = input("Choice: ")
    elif b == 5:
        print "The base and circumference of a cone can be found with the circle formulas, so they aren't found here."
        print "1) Lateral Area"
        print "2) Total Area"
        print "3) Volume"
        print "4) Shapes Menu"
        opt = input("Choice: ")
        if opt == 1:
           r = input("Radius: ")
           sl = input("Slant height: ")
           print "The Lateral Area is: ",1/2*(2*3.14*r)*sl
           print shape_menu()
        elif opt == 2:
           r = input("Radius: ")
           sl = input("Slant height: ")
           print "The total area is: ",1/2*(2*3.14*r)*sl+(3.14*(r**2))
           print shape_menu()
        elif opt == 3:
           height = input("Height: ")
           r = input("Radius: ")
           print "The volume is: ",1/4*(3.14*(r**2))*height
           print shape_menu()
        elif opt == 4:
           print shape_menu()
        else:
           print "That's not an option"
           opt = input("Choice: ")
    elif b == 6:
        print "1) Lateral Area"
        print "2) Total Area"
        print "3) Volume"
        print "4) Shape Menu"
        g = input("Choice: ")
        if g == 1:
           r = input("Radius: ")
           height = input("Height: ")
           print "The Lateral Area is: ",(2*3.14*r)*height
           print shape_menu()
        elif g == 2:
           r = input("Radius: ")
           height = input("Height: ")
           print "The Total Area is: ",((2*3.14*r)*height)+(2*(3.14*(r**2)))
           print shape_menu()
        elif g == 3:
           r = input("Radius: ")
           height = input("Height: ")
           print "The volume is: ",(3.14*(r**2))*height
           print shape_menu()
        elif g == 4:
           print shape_menu()
        else:
           print "That is not an option!"
           g = input("Choice: ")
    elif b == 7:
        print "1) Arc Length"
        print "2) Area"
        print "3) Shape Menu"
        h = input("Choice: ")
        if h == 1:
           diam = input("Diameter: ")
           print "The arc length is: ",(3.14*diam)/2
           print shape_menu()
        elif h == 2:
           r = input("Radius: ")
           print "The area is: ",(3.14*(r**2))/2
           print shape_menu()
        elif h == 3:
           print shape_menu
        else:
           print "Sorry, incorrect entry. Please try again."
           h = input("Choice: ")
    elif b == 8:
        print main_menu()
    else:
        print "Sorry, not an option."
        print shape_menu()
elif option == 3:
    print temp_menu()
    if temp_option == 1:
        print "Convert degrees Kelvin to degrees Celsius."
        k = input("Degrees Kelvin: ")
        print k-273.16," degrees Celsius"
        print temp_menu()
    elif temp_option == 2:
      print "Convert Fahrenheit to Celsius"
      f = input("Degrees Fahrenheit: ")
      print 5/9*(f-32)," degrees Celsius"
      print temp_menu()
    elif temp_option == 3:
      print "Convert Celsius to Fahrenheit"
      c = input("Degrees Celsius: ")
      print (9/5*C)+32," degrees Fahrenheit"
      print temp_menu()
    elif temp_option == 4:
      print "Convert degrees Celsius to degrees Kelvin"
      c = input("Degrees Celsius: ")
      print c+273.16," degrees Kelvin"
      print temp_menu()
    elif temp_option == 5:
      print "Convert degrees Kelvin to Fahrenheit"
      k = input("Degrees Kelvin: ")
      print ((k-273.16)*9/5)+32," degrees Fahrenheit"
      print temp_menu()
    elif temp_option == 6:
      print "Convert Fahrenheit to degrees Kelvin"
      f = input("Degrees Fahrenheit: ")
      print (5/9*(f-32))+273.16," degrees Kelvin"
      print temp_menu()
    elif temp_option == 7:
      print main_menu()
    else:
      print "That's not an option. Please try again"
      print temp_menu()
elif option == 4:
   print formula_menu()
   if formula_option == 1:
      p = input("Principal: ")
      r = input("Rate as a decimal: ")
      t = input("Time in years: ")
      print "Interest: ",p*r*t
      print formula_menu()
   elif formula_option == 2:
      r = input("Rate: ")
      t = input("Time: ")
      print "Distance: ",r*t
      print formula_menu()
   elif formula_option == 3:
      v = input("Velocity: ")
      t = input("Time: ")
      print "Uniform motion: ",v*t
      print formula_menu()
   elif formula_option == 4:
      m = input("Mass: ")
      v = input("Velocity: ")
      print "Momentum: ",m*v
      print formula_menu()
   elif formula_option == 5:
      as = input("Acceleration speed: ")
      t = input("Time: ")
      print "Uniformly accelerated motion: ",1/2*as*t
      print formula_menu()
   elif formula_option == 6:
      gravity = input("Constant acceleration due to gravity: ")
      t = input("Time: ")
      print "Distance covered by falling body: ",1/2*gravity*(t**2)
      print formula_menu()
   elif formula_option == 7:
      m = input("Mass: ")
      gravity = input("Gravity: ")
      print "Weight: ",m*gravity
      print formula_menu()
   elif formula_option == 8:
      print main_menu()
   else:
      print "That is not an option."
      print formula_menu()
elif option == 5:
   print "Goodbye!"
else:
   print "That is not an option. Please choose an option from the menu."
   print main_menu()
print

Any help will be appreciated!
Nathan Pinno
http://www.npinnowebsite.ca/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050709/765d7ef0/attachment-0001.htm


More information about the Tutor mailing list