# [Tutor] Giant Calc runs, but need advice on how to make the menu repopup.

Pujo Aji ajikoe at gmail.com
Tue Jul 12 10:33:03 CEST 2005

```you can wrap your code with while statement that check a user input
received at the end of every calculation you made whether go back to
main menu or not.

pujo

On 7/12/05, Nathan Pinno <falcon3166 at hotmail.com> wrote:
>
> It runs but now how do I make it go back to the previous menu (e.g. from Add
> to Calculate Menu?)
>
> Here is the latest screenshot:
>
> The Giant Calculator
>
> Copyright 2005 Written and debugged by Nathan Pinno
>
> 1) Calculate
> 2) Shapes
> 3) Temperature
> 4) Formulas
> 5) Quit
> What option would you like:1
> 2) Subraction
> 3) Multiplication
> 4) Division w/o remainder
> 5) Division with remaider
> 6) Exponation
> 7) Square roots
> 8) Back to the previous menu.
> What option would you like:3
> First number:3
> Second number:2
> 3 * 2 =  6
> 2) Subraction
> 3) Multiplication
> 4) Division w/o remainder
> 5) Division with remaider
> 6) Exponation
> 7) Square roots
> 8) Back to the previous menu.
> What option would you like:7
>
>
> >>>
>
> and the current 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.
>    global option
>    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:" )
>
>     global cal_opt
>     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."
>     cal_opt = input("What option would you like:" )
>
>     global shape_opt
>     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"
>     shape_opt = input("What option would you like?" )
>
>     global temp_opt
>     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: ")
>
>     global formula_opt
>     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
> if option == 1:
>     if cal_opt == 1:
>         X = input("First number:" )
>         Y = input("Second number:" )
>         print X, "+", Y, "= ",X + Y
>     elif cal_opt == 2:
>         X = input("First number:" )
>         Y = input("Second number:" )
>         print X, "-", Y, "= ",X - Y
>     elif cal_opt == 3:
>         X = input("First number:" )
>         Y = input("Second number:" )
>         print X, "*", Y, "= ",X * Y
>     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
>     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
>     elif cal_opt == 6:
>         X = input("First number:" )
>         Y = input("Power:" )
>         print X, "**", Y, "= ",X**Y
>     elif cal_opt == 7:
>         X = input("Number to be squared:" )
>         print "The square root of", X, " = ",X**0.5
>     elif cal_opt == 8:
>     else:
>         print "That's not an option. Try again."
> elif option == 2:
>     if shape_opt == 1:
>         print "1) Circumference"
>         print "2) Area"
>         print "3) Shapes Menu"
>         op = input("Choice: ")
>         if op == 1:
>             side = input("Side: ")
>             print "Circumference = ",4*side
>         elif op == 2:
>             side = input("Side: ")
>             print "Area = ",side**2
>         elif op == 3:
>         else:
>             print "That's not an option."
>             op = input("Choice: ")
>     elif shape_opt == 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
>         elif d == 2:
>             print "The area of the circle is ",3.14*(radius**2)
>         elif d == 3:
>         else:
>             print "That's not an option."
>             d = input("Choice: ")
>     elif shape_opt == 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
>         elif g == 2:
>             base = input("Base: ")
>             altitude = input("Altiutude: ")
>             print "The perimeter of the rectangle is:
> ",(2*base)+(2*altitude)
>         elif g == 3:
>         else:
>            print "That's not an option."
>            g = input("Choice: ")
>     elif shape_opt == 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
>         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
>         elif e == 3:
>             base = input("Base: ")
>             height = input("Height: ")
>             print "The area of the triangle is: ",1/2*base*height
>         elif e == 4:
>         else:
>             print "That's not an option! Try again."
>             e = input("Choice: ")
>     elif shape_opt == 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
>         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))
>         elif opt == 3:
>            height = input("Height: ")
>            r = input("Radius: ")
>            print "The volume is: ",1/4*(3.14*(r**2))*height
>         elif opt == 4:
>         else:
>            print "That's not an option"
>            opt = input("Choice: ")
>     elif shape_opt == 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
>         elif g == 2:
>            r = input("Radius: ")
>            height = input("Height: ")
>            print "The Total Area is: ",((2*3.14*r)*height)+(2*(3.14*(r**2)))
>         elif g == 3:
>            r = input("Radius: ")
>            height = input("Height: ")
>            print "The volume is: ",(3.14*(r**2))*height
>         elif g == 4:
>         else:
>            print "That is not an option!"
>            g = input("Choice: ")
>     elif shape_opt == 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
>         elif h == 2:
>            r = input("Radius: ")
>            print "The area is: ",(3.14*(r**2))/2
>         elif h == 3:
>         else:
>            print "Sorry, incorrect entry. Please try again."
>            h = input("Choice: ")
>     elif shape_menu == 8:
>     else:
>         print "Sorry, not an option."
> elif option == 3:
>     if temp_option == 1:
>         print "Convert degrees Kelvin to degrees Celsius."
>         k = input("Degrees Kelvin: ")
>         print k-273.16," degrees Celsius"
>     elif temp_option == 2:
>       print "Convert Fahrenheit to Celsius"
>       f = input("Degrees Fahrenheit: ")
>       print 5/9*(f-32)," degrees Celsius"
>     elif temp_option == 3:
>       print "Convert Celsius to Fahrenheit"
>       c = input("Degrees Celsius: ")
>       print (9/5*C)+32," degrees Fahrenheit"
>     elif temp_option == 4:
>       print "Convert degrees Celsius to degrees Kelvin"
>       c = input("Degrees Celsius: ")
>       print c+273.16," degrees Kelvin"
>     elif temp_option == 5:
>       print "Convert degrees Kelvin to Fahrenheit"
>       k = input("Degrees Kelvin: ")
>       print ((k-273.16)*9/5)+32," degrees Fahrenheit"
>     elif temp_option == 6:
>       print "Convert Fahrenheit to degrees Kelvin"
>       f = input("Degrees Fahrenheit: ")
>       print (5/9*(f-32))+273.16," degrees Kelvin"
>     elif temp_option == 7:
>     else:
>       print "That's not an option. Please try again"
> elif option == 4:
>    if formula_option == 1:
>       p = input("Principal: ")
>       r = input("Rate as a decimal: ")
>       t = input("Time in years: ")
>       print "Interest: ",p*r*t
>    elif formula_option == 2:
>       r = input("Rate: ")
>       t = input("Time: ")
>       print "Distance: ",r*t
>    elif formula_option == 3:
>       v = input("Velocity: ")
>       t = input("Time: ")
>       print "Uniform motion: ",v*t
>    elif formula_option == 4:
>       m = input("Mass: ")
>       v = input("Velocity: ")
>       print "Momentum: ",m*v
>    elif formula_option == 5:
>       as = input("Acceleration speed: ")
>       t = input("Time: ")
>       print "Uniformly accelerated motion: ",1/2*as*t
>    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)
>    elif formula_option == 7:
>       m = input("Mass: ")
>       gravity = input("Gravity: ")
>       print "Weight: ",m*gravity
>    elif formula_option == 8:
>    else:
>       print "That is not an option."
> elif option == 5:
>    print "Goodbye!"
> else:
>    print "That is not an option. Please choose an option from the menu."
> print
>
>
> So how do I do it?
>
> Nathan Pinno
> http://www.npinnowebsite.ca/
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
```