【发布时间】:2018-11-04 07:38:06
【问题描述】:
number = int(input("Enter the number of parcels you want to input: "))
width = int(input("Enter the width (cm)of the parcel: "))
length = int(input("Enter the length (cm)of the parcel: "))
height = int(input("Enter the height (cm)of the parcel: "))
weight = int(input("Enter the weight (kg) of the parcel: "))
width_list = []
length_list = []
height_list = []
weight_list = []
parcel_number = []
parcel_number.append(number)
if width > 80 or width < 1:
print("Only widths between 1-80 cm is acceptable")
elif height > 80 or height < 1:
print("Only heights between 1-80 cm is acceptable")
elif length > 80 or length < 1:
print("Only lengths between 1-80 cm is acceptable")
elif weight > 10 or weight < 1:
print("Only allowed weights between 1-10 kg")
else:
print("Parcel is acceptable")
首先我要求用户添加包裹的尺寸。然后我需要检查每个包裹的尺寸是否在正确的 1-80 厘米之间,重量是否在 1-10 公斤之间,然后如果用户输入的尺寸超出限制,则需要打印错误。如果包裹是可以接受的,我应该将每个测量值附加到下面的列表中,但我不知道该怎么做,接受 parcel_number。如果可能的话,你能帮我把代码放在一个循环中,以便我运行它附加到 parcel_number 列表的次数吗?谢谢!
【问题讨论】:
-
您应该查看有关 python for-loops 的文档! :)
标签: python list loops for-loop while-loop