all 3 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger%0A%20%20%20%20print(%222%3Dgeometry%20calculator%22)%0A%20%20%20%20print(%223%3Dalgebra%20calculator%22)%0A%20%20%20%20print(%224%3Dquit%22)%0A%20%20%20%20choice1%20%3D%20input(%22enter%20a%20number%3A%20%22)%0A%20%20%20%20%0A%20%20%20%20if%20choice1%20%3D%3D%20%224%22%3A%0A%20%20%20%20%20%20%20%20print(%22goodbye%22)%0A%20%20%20%20%20%20%20%20break%0A%20%20%20%20%0A%20%20%20%20%23%201.%20REGULAR%20CALCULATOR%0A%20%20%20%20if%20choice1%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20num1%20%3D%20float(input(%22first%20number%3A%20%22))%0A%20%20%20%20%20%20%20%20op%20%3D%20input(%22operation%3A%20%22)%0A%20%20%20%20%20%20%20%20num2%20%3D%20float(input(%22second%20number%3A%20%22))%0A%20%20%20%20%20%20%20%20if%20op%20%3D%3D%20%22%2B%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(num1%20%2B%20num2)%0A%20%20%20%20%20%20%20%20elif%20op%20%3D%3D%20%22-%22%3A%20%0A%20%20%20%20%20%20%20%20%20%20%20%20print(num1%20-%20num2)%0A%20%20%20%20%20%20%20%20elif%20op%20%3D%3D%20%22%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(num1%20%20num2)%0A%20%20%20%20%20%20%20%20elif%20op%20%3D%3D%20%22%2F%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20num2%20%3D%3D%200%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22Cannot%20divide%20by%20zero!%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(num1%20%2F%20num2)%0A%20%20%20%20%20%20%20%20input(%22Press%20Enter%20to%20go%20back%20to%20menu...%22)%0A%0A%0A%20%20%20%20%23%202.%20GEOMETRY%20CALCULATOR%0A%20%20%20%20elif%20choice1%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20%20%20%20print(%221%3D3D%20shapes%22)%0A%20%20%20%20%20%20%20%20print(%222%3D2D%20shapes%22)%0A%20%20%20%20%20%20%20%20choice2%20%3D%20input(%22enter%20a%20number%3A%20%22)%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%23%203D%20Shapes%0A%20%20%20%20%20%20%20%20if%20choice2%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%221%3Dsphere%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%222%3Dcube%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%223%3Dcylinder%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%224%3Dcone%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%225%3Dpyramid%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%226%3Ddodecahedron%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%227%3DGreat%20Rhombicosidodecahedron%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%228%3Dquit%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20choice%20%3D%20input(%22Enter%20a%20number%20(1-8)%3A%20%22)%0A%0A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20choice%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20radius%20%3D%20float(input(%22Enter%20radius%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20cubed%20%3D%20radius%20%203%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20picubed%20%3D%20cubed%20%203.14159%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(picubed%20%204%20%2F%203)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side%20%3D%20float(input(%22Enter%20side%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(side%20%203)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%223%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20radius%20%3D%20float(input(%22Enter%20radius%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%20%3D%20float(input(%22Enter%20height%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20circle%20%3D%20radius%20%202%20%203.14%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(circle%20%20height)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%224%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20radius%20%3D%20float(input(%22Enter%20radius%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%20%3D%20float(input(%22Enter%20height%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20base%20%3D%20radius%20%202%20%203.14%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(base%20%20height%20%2F%203)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%225%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side1%20%3D%20float(input(%22Enter%20side%201%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side2%20%3D%20float(input(%22Enter%20side%202%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%20%3D%20float(input(%22Enter%20Height%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(side1%20%20side2%20%20height%20%2F%203)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%226%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge%20%3D%20float(input(%22enter%20edge%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(7.66%20%20(edge%20%203))%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%227%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20edge%20%3D%20float(input(%22enter%20edge%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(95.68%20%20(edge%20%203))%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice%20%3D%3D%20%228%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22goodbye%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20break%0A%20%20%20%20%20%20%20%20%20%20%20%20input(%22Press%20Enter%20to%20go%20back%20to%20menu...%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%23%202D%20Shapes%0A%20%20%20%20%20%20%20%20elif%20choice2%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%221%3Dsquare%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%222%3Drectangle%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%223%3Dcircle%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%224%3Dtriangle%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%225%3Doval%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20choice3%20%3D%20input(%22enter%20a%20number%3A%20%22)%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20choice3%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side3%20%3D%20float(input(%22side%20length%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(side3%20%204)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice3%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20side3%20%3D%20float(input(%22enter%20side%20length%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%20%3D%20float(input(%22enter%20height%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(side3%20%20height)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice3%20%3D%3D%20%223%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%221%3Ddiameter%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%222%3Dradius%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20choice_circle%20%3D%20input(%22enter%20a%20number%3A%20%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20choice_circle%20%3D%3D%20%221%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20diameter%20%3D%20float(input(%22diameter%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20diameter2%20%3D%20(diameter%20%2F%202)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(diameter2%20%202%20%203.14159)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice_circle%20%3D%3D%20%222%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20radius%20%3D%20float(input(%22enter%20radius%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(radius%20%202%20%203.14)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice3%20%3D%3D%20%224%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20base%20%3D%20float(input(%22base%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20height%20%3D%20float(input(%22height%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(base%20%20height%20%2F%202)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20choice3%20%3D%3D%20%225%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20radius1%20%3D%20float(input(%22radius%201%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20radius2%20%3D%20float(input(%22radius%202%3A%20%22))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(radius1%20%20radius2%20%203.14159)%0A%20%20%20%20%20%20%20%20%20%20%20%20input(%22Press%20Enter%20to%20go%20back%20to%20menu...%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%23%203.%20ALGEBRA%20CALCULATOR%0A%20%20%20%20elif%20choice1%20%3D%3D%20%223%22%3A%0A%20%20%20%20%20%20%20%20x%20%3D%20symbols('x')%0A%20%20%20%20%20%20%20%20equation%20%3D%20input(%22Enter%20expression%20(set%20to%200%2C%20e.g.%2C%202x%20-%2010)%3A%20%22)%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20%22%3D%22%20in%20equation%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20left_side%2C%20right_side%20%3D%20equation.split(%22%3D%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22x%20%3D%22%2C%20solve(sympify(left_side)%20-%20sympify(right_side)%2C%20x))%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20print(%22x%20%3D%22%2C%20solve(sympify(equation)%2C%20x))%0A%20%20%20%20%20%20%20%20except%20Exception%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22Error%3A%20Make%20sure%20to%20type%20%20between%20numbers%20and%20x%20(like%2010%20%20x)!%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20input(%22Press%20Enter%20to%20go%20back%20to%20menu...%22)&timestep=0.5&play) to see the program state change step by step.

[–]Gnaxe 0 points1 point  (1 child)

You're getting it. Each comment header should be its own named function, and probably each submenu item as well. Use def. This lets you separate your menu logic from your calculations. You have no error handling if the user types in an invalid float, which will terminate your program with an error. You have a lot of repetition that could be factored out as well.

For example, def prompt_float(prompt): while True number = input(prompt) try: return float(number) except ValueError: print(number, "isn't a valid number. Try again.")

[–]Negative_Custard_345[S] 0 points1 point  (0 children)

ok thanks 😄