我做了一個簡單的python加速計算器,但我遇到的問題是讓程序返回到開始或退出。我希望用戶能夠點擊'1'並重新啓動計算器或點擊'2'並讓程序退出。我似乎無法弄清楚如何運行我的主要功能後,程序已經通過公式,有什麼建議?謝謝。在Python中重新啓動我的加速計算器?
class equation():
def main():
Calc()
while True:
restart = input("Would you like to run again? If yes press '1' if you wish to Exit press '2'")
if restart==1:
Calc()
else:
print "Goodbye"
break
print "What is your Velocity: "
v = float(input()) #m/s
print "What is your Intial Velocity: "
u = float(input()) #m/s
print "What is the time: "
t = float(input()) #Seconds
aa = v-u
answer = aa/t
eq=equation()
print "Your Acceleration is: ", eq.answer, "m/s^2"
print eq.main
'if restart =='1':'它應該工作,如果它是Python 2,7,則使用'raw_input'。 –