python实现程序重启_如何让python程序重新启动到某一行?

您将需要添加一种方法,让用户退出并中断循环,但while True将循环多长时间。在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:

.....

如果要使用循环,还可以使用try/except验证用户是否只输入了有效的输入:

^{pr2}$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值