def temperature_def(tem):
try:
if tem >= 34 and tem <= 38:
return tem
else:
print("You can not enter the list!")
quit()
except:
print("Enter a number!")
quit()
pearson1 = People_class((input("Name and Surname (with out accents): ").lower()), int(input("Age: ")),
covid_status_def(input("Someone close to you either has covid or had it? ").lower().strip()),
temperature_def(float(input("What is your temperature in degrees? "))))
这里我试图为if语句获取一个数字,我在最后一行输入
try and except应该识别是否输入了数字(不知道这是否是一个单词),并且应该按照下面的操作,但是,当我输入的不是数字的内容时,它会出现错误
为了澄清,我正在做一个列表,“float(input(…)”不能移动(据我所知)
提前感谢,节日快乐:D
这是因为您正显式地尝试将用户输入转换为浮点:
您应该从上面删除
float
,并在不进行任何显式转换的情况下传递输入。如果输入不正确,在方法中定义的try-except
将处理它编辑:由于从
input
中删除了浮点对流,现在必须将其放入try
块中:相关问题 更多 >
编程相关推荐