0

I'm trying to figure out how to return my script back to line 1 which is basically the main menu. It is the last part I need to make sure the program runs correctly but I am new to programming and can't quite finish this last detail. I have attached the script below. Any and all help would be greatly appreciated.

print("Select the calculator you would like to use.\n")
print("1.  PSI Calculation                    11.  CU-IN/REV")
print("2.  Torque Force                       12.  CC/REV")
print("3.  Horsepower Applied                 13.  Torque Applied")
print("4.  Flow Rate                          14.  Stroke Time")
print("5.  Gallons Per Minute                 15.  Blind End Cylinder Area")
print("6.  Tine Shaft Bend                    16.  Rod End Cylinder Area")
print("7.  Electric Horsepower")
print("8.  Fluid Horsepower ")
print("9.  Motor Speed (Flow) ")
print("10. Cylinder Force\n")
greeting = input("Enter your selection here:")
selection = float(greeting)

if selection == 1:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("\nEnter the values below for PSI calculation.\n" )

  Flow = input("Enter Flow:")
  Restriction = input("Enter Restriction:")

  psi_calculation = float(float(Flow) * float(Restriction))
  print("\nPSI Calculation =" , psi_calculation)

elif selection == 2:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Torque Force.\n" )

  Pressure = input("Enter PSI:")
  Displacement = input("Enter Displacement(CU-IN/REV):")

  torque_force = float(float(Pressure) * float(Displacement) / 6.28)
  print("\nTorque Force (IN. LBS.):" , torque_force)

elif selection == 3:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Horsepower Applied.\n" )

  IN_LBS = input("Enter IN. LBS.:")
  RPM = input("Enter RPM:")

  horsepower_applied = float(float(IN_LBS) * float(RPM) / 63025)
  print("\nHorsepower Applied:" , horsepower_applied)

elif selection == 4:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Flow Rate.\n" )

  Velocity = input("Enter Velocity(FT/S):")
  Area = input("Enter Area(IN²):")

  flow_rate = float(float(Velocity) * float(Area) / 0.3208)
  print("\nFlow Rate:" , flow_rate)

elif selection == 5:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Gallons Per Minute.\n" )

  Pump_RPM = input("Enter Pump RPM:")
  Displacement = input("Enter Displacement(CU-IN/REV):")

  GPM = float(float(Pump_RPM) * float(Displacement) / 231 * 0.8)
  print("\nGallons Per Minute:" , GPM)

elif selection == 6:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Tine Shaft Bend.\n" )

  Tine_Max_Load = input("Enter Tine Max Load:")
  Length_To_Load_Point = input("Enter Length To Load Point:")
  Riser_Height = input("Riser Height:")

  Tine_Shaft_Bend = float(float(Tine_Max_Load) * float(Length_To_Load_Point) / float(Riser_Height))
  print("\nTine Shaft Bend:" , Tine_Shaft_Bend)

elif selection == 7:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Electric Horsepower.\n" )

  Volts = input("Enter Volts:")
  Amps = input("Enter Amps:")
  Efficiency = input("Efficiency:")

  Electric_Horsepower = float(float(Volts) * float(Amps) * float(Efficiency) / 746)
  print("\nElectric Horsepower:" , Electric_Horsepower)

elif selection == 8:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Fluid Horsepower.\n" )

  Pressure = input("Enter PSI:")
  GPM = input("Enter GPM:")
  Efficiency = input("Efficiency:")

  Fluid_Horsepower = float(float(Pressure) * float(GPM) * float(Efficiency) / 1714)
  print("\nFluid Horsepower:" , Fluid_Horsepower)

elif selection == 9:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Motor Speed (Flow).\n" )

  GPM = input("Enter GPM:")
  Displacement = input("Enter Displacement:")
  Efficiency = input("Efficiency:")

  Motor_Speed = float((231 * float(GPM)) / float(Displacement) * float(Efficiency))
  print("\nMotor Speed (Flow):" , Motor_Speed)

elif selection == 10:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Cylinder Force(Lbs.).\n" )

  Pressure = input("Enter PSI:")
  Cylinder_Area = input("Enter Cylinder Area:")

  Cylinder_Force = float(float(Pressure) * float(Cylinder_Area))
  print("\nCylinder Force(Lbs.):" , Cylinder_Force)

elif selection == 11:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate CU-IN/REV.\n" )

  CC_REV = input("Enter CC/REV:")

  CU_IN = float(float(CC_REV) * 0.0610237)
  print("\nCU-IN/REV:" , CU_IN)

elif selection == 12:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate CC/REV.\n" )

  CU_IN = input("Enter CU-IN/REV:")

  CC_REV = float(float(CU_IN) * 16.3871)
  print("\nCC/REV:" , CC_REV)

elif selection == 13:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Torque Applied.\n" )

  Horsepower = input("Enter Horsepower:")
  RPM = input("Enter RPM:")

  Torque_Applied = float(float(Horsepower) * 63025 / float(RPM))
  print("\nTorque Applied(IN. LBS.):" , Torque_Applied)

elif selection == 14:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Stroke Time.\n" )

  Area = input("Enter Area:")
  Stroke = input("Enter Stroke:")
  GPM = input("Enter GPM:")

  Stroke_Time = float(float(Area) * float(Stroke) * 0.26 / float(GPM))
  print("\nStroke Time:" , Stroke_Time)

elif selection == 15:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("Enter the values below to calculate Blind End Cylinder Area.\n" )

  Piston_Diameter = input("Enter Piston Diameter:")
  Radious = float(Piston_Diameter) / 2
  R_Squared = float(Radious * Radious)

  print("Radious:" , Radious)
  print("Radious Squared:" , R_Squared)

  BECA = float(float(R_Squared) * 3.1415)
  print("\nBlind End Cylinder Area:" , BECA)

elif selection == 16:
  import os
  os.system('cls' if os.name == 'nt' else "printf '\033c'")
  print("To calculate the Rod End Cylinder Area we must first calculate the Blind End Cylinder Area.\n" )

  Piston_Diameter = input("Enter Piston Diameter:")
  Radious = float(Piston_Diameter) / 2
  R_Squared = float(Radious * Radious)

  BECA = float(float(R_Squared) * 3.1415)
  print("\nBlind End Cylinder Area:" , BECA)

  print("Enter the values below to calculate Rod End Cylinder Area.\n" )

  print("Blind End Cylinder Area:" , BECA)
  Rod_Diameter = input("Enter Rod Diameter:")
  Radious = float(Rod_Diameter) / 2
  R_Squared = float(Radious * Radious)
  Rod_Area = float(R_Squared) * 3.1415
  print("Radious:" , Radious)
  print("Radious Squared:" , R_Squared)
  print("Rod Area:" , Rod_Area)

  RECA = float(BECA - Rod_Area)
  print("\nRod End Cylinder Area:" , RECA)

else:
  print("\nERROR, SELECTION OUT OF RANGE.")
mjack360
  • 1
  • 3
  • put all in a function and call that function in a while loop. – Shivendra Pratap Kushwaha Oct 08 '21 at 19:32
  • You can't. If you want to repeat code you have to create the appropriate control structures like functions and loops. – Klaus D. Oct 08 '21 at 19:32
  • Welcome to Stack Overflow. Please note that [you are expected to do some research before asking](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users), and it is helpful to [understand the fundamentals of the language first](https://docs.python.org/3/tutorial/index.html) - Stack Overflow is not a tutorial resource. I found two of the linked duplicates by literally copying and pasting your question title into a search engine. Please also read https://stackoverflow.com/help/minimal-reproducible-example . – Karl Knechtel Oct 08 '21 at 19:34
  • 1
    When writing questions, use minimal examples that demonstrate the problem. We don't need a thousand lines of code when a few will do. – tdelaney Oct 08 '21 at 19:34
  • you don't need to `import os` in each `if statement`, do it once at the start of the file and the third `float around everything` is redundant: `float(float(Flow) * float(Restriction))` – Matiiss Oct 08 '21 at 19:35
  • I figured there were going to be a couple of things that I did that didn't need to be done. I'm new at this so just getting it to work at all made me happy. – mjack360 Oct 08 '21 at 19:52

0 Answers0