3 回答

TA贡献1836条经验 获得超4个赞
在获得有效(或无效)输入之前,您已经知道如何循环。要检测整数,您可以尝试将输入转换为int
try:
value = int(fqas_no)
except:
# loop around to try again
更好的是,使用内置方法
if fqas_no.isdigit():

TA贡献1810条经验 获得超4个赞
查看有关异常处理的文档。您需要包含一条try声明:
try:
if 50 <= fqas_no :
#etc
except ValueError:
print("Numbers only please")
这两个在一起。只是except不正确的语法。
旁注,您应该调用lower()输入本身。这样,您的代码将更加简洁:
while fqas not in ["yes", "no"]:
fqas = input(">>> (yes/no): ").lower()
if fqas == "yes":
#etc

TA贡献1921条经验 获得超9个赞
没有尝试的除外部分似乎是您的问题。
base_pay = 1000
fqas = None
while fqas not in ("yes", "no", "Yes", "No"):
fqas = input(">>> [yes/no]: ")
if fqas.lower() == "yes":
print("\nAwesome! Current pay: $", base_pay + 50)
elif fqas.lower() == "no":
try:
fqas_no = int(input("if not, how much do you think she deserve? \n>>>"))
except ValueError:
print('Numbers only please')
break
if 50 <= fqas_no:
print("AMAZINGGGG! current pay: $", base_pay + fqas_no)
continue
elif fqas_no <= 50:
print("That's cool, current pay: $", base_pay + fqas_no)
continue
这应该可以解决您的问题。
添加回答
举报