python怎么回到开头_python-3.x

我有几个if语句,但是如果第一个输入为false,它仍将继续执行下一个if语句,而不是回到该if语句的开头并重新开始。

下面的代码

# check the weight of a single parcel

while True:

pweight = float(input('How much does your parcel weigh in kg? '))

if pweight > 10:

print('Sorry the parcel is to heavy')

elif pweight < 1:

print('Sorry the parcel is to light')

else:

break

print('----------------------------------------------')

while True:

height1 = float(input('Enter the parcel height in cm: '))

if height1 > 80:

print('Sorry, Your height is too large')

else:

break

print('----------------------------------------------')

while True:

width1 = float(input('Enter the parcel width in cm: '))

if width1 > 80:

print('Sorry, Your width is too large')

else:

break

print('----------------------------------------------')

while True:

length1 = float(input('Enter the parcel length in cm: '))

if length1 > 80:

print('Sorry, Your length is too large')

else:

break

print('----------------------------------------------')

while True:

if (height1 + width1 + length1) > 200:

print('Sorry, the sum of your dimensions are too large')

else:

print('Your parcels dimensions are', height1, 'x', width1, 'x', length1)

print('Your parcel has been accepted for delivery, many thanks for using our service :)')

break

例如,如果输入的体重是11或身高大于80,则应始终回到起点并询问体重。 **如果没有满足任何条件,我需要重新回到开始并要求重量。 **程序应重新启动并再次询问重量。

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值