【发布时间】:2020-08-13 13:40:44
【问题描述】:
我正在做一个用户必须输入值的项目。如果用户键入超过 300 的值 3 次,则循环应该结束。如果用户键入的值小于 300,则应提示警告消息。另一个标准是,如果用户不满足上述条件,我需要允许用户退出循环。目前,我尝试使用列表来完成,但我的代码似乎没有计算输入的数量。
list1 = list()
counter = 1
while counter <= 3:
ask = float(input("Please enter each of the value: "))
while ask != "":
list1.append(str(ask))
ask = float(input("Please enter each of the value: "))
if ask >= 50:
counter += 1
else:
print("Value must be more than 300. If you do not meet the criteria, please press 'enter'. ")
print(list1)
以下代码是我的原始代码,没有考虑最小输入值。
counter = 1
while counter <= 3:
ask = float(input("Please enter each of the value: "))
if ask >= 50:
counter += 1
else:
print("Value must be more than 300 ")
如果有人能帮助我,我将不胜感激。
【问题讨论】:
标签: python python-3.x loops if-statement while-loop