python实现程序重启_如何让python程序重新启动到某一行?
您將需要添加一種方法,讓用戶退出并中斷循環(huán),但while True將循環(huán)多長(zhǎng)時(shí)間。在while True:
# let user decide if they want to continue or quit
x = input("Pick a number from (1,2,3,4) or enter 'q' to quit:")
if x == "q":
print("Goodbye")
break
x = int(x)
if x == 1:
print ("You are finding the Radius.")
ra = int(input("Enter the arch length: "))
rd = int(input("Enter the degree: "))
rr = ra/math.radians(rd)
print ("The Radius is:",rr)
elif x == 2: # use elif, x cannot be 1 and 2
print ("You are finding the Arch Length.")
sr = int(input("Enter the radius: "))
sd = int(input("Enter the degree: "))
ss = math.radians(sd)*sr
print ("The Arch Length is:",ss)
elif x == 3:
.....
elif x == 4:
.....
如果要使用循環(huán),還可以使用try/except驗(yàn)證用戶是否只輸入了有效的輸入:
^{pr2}$
總結(jié)
以上是生活随笔為你收集整理的python实现程序重启_如何让python程序重新启动到某一行?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql国际化_Java的Struts
- 下一篇: java thread类_java多线程