我想重置/重新启动我的程序,但基于用户输入。因此,假设用户键入“yes”并单击enter,程序将重置/重新启动并重新启动。我正在做一个能量计算器;物理问题。输出是机械能、动能和势能。所有的公式都正确编码,一切都按预期工作,除了我没有办法重新启动程序,不点击回文件并重新打开。#Importing "time" and "math" so I can use the time.sleep and rounding functions
import time
import math
restart=1
user_r1=float(input ("What is the mass of your object (kg) = "))
print ("")
user_r2=float(input ("Whats is the height you are dropping from (m) = "))
print ("")
user_r3=float(input ("What is the velocity (m/s) = "))
#Formulas that solve from the inputs given
EKinetic = 0.5 * user_r1 * user_r3 * user_r3
EPotential = user_r1 * 9.81 * user_r2
MechEnergy = (EPotential) + (EKinetic)
#Rounding - To change the ammount of sigdigs change the # infront of the f'
EKinetic='%.1f' % EKinetic
EPotential='%.1f' % EPotential
MechEnergy='%.1f' % MechEnergy
#Spitting out the info the user will see
print ("")
print ("===============================================================================")
print ("Kinetic Energy = ",EKinetic,"J")
print ("")
print ("Potential Energy = ",EPotential,"J")
print ("")
print ("Mechanical Energy = ",MechEnergy,"J")
print ("===============================================================================")
print ("")
#This time.sleep will make the program pause for (x# of seconds)
time.sleep(3)
user_r4=(input ("To do another calculation type yes and hit enter = "))
if user_r4 == ("yes"):
print ("YAY")
###PUT RESTART CODE HERE###
###EVERYTHING DOWN ARE JUST PLACE HOLDERS FOR THE RESTART CODE###
else:
print ("Please type yes to continue")
time.sleep(1)
user_r4=(input ("To do another calculation type yes and hit enter = "))
if user_r4 == ("yes"):
print ("YAY")
###PUT RESTART CODE HERE###
else: print ("Thats enough!!!")
time.sleep(3)