我遇到了一个我搞不懂的小问题。我被困在了一个时间循环里。我有3个while循环,第一个循环按计划执行,然后进入第二个循环。但是它被卡在了第二个,我不知道为什么。
对我想要做的事情做一个小小的解释:
我应该得到3个输入:经验年(年份)、性能(性能)和在1-10(级别)之间随机生成的int。该程序将询问用户的经验,如果它是3-11之间,他们是合格的。如果没有,它会告诉他们他们没有资格,并要求重新输入一个值.表演也是一样。如果他们输入一个小于或等于11的数字,它将生成随机整数(级别),在此点水平将用于评估他们的奖金。用户将得到提示以获得体验,并将正确地工作并继续执行。然而,即使输入一个有效的输入,它也不断要求他们重新输入性能#。我搞不懂它为什么会被困在这里。
import random
error = True
expError = True
performanceError = True
# Get users name
name = input("Enter your name: ")
# Get users experience *MINIMUM of 3 yrs py
while (expError):
try:
yearsexp = int (input(name+", Enter the years of your experience: "))
if (yearsexp >= 3 and yearsexp <= 11):
expError = False
print(name, "You are qualified")
else:
raise ValueError
except:
print ("You have entered an invalid number! Try again...")
#Get users performance
while (performanceError):
try:
performance = int (input(name+", Enter the performance: "))
if (performance <= 11):
expError = False
print(name, "You are qualified")
else:
raise ValueError
except:
print ("You have entered an invalid number! Try again...")
performanceError = False
# Get random level number
level = random.randint(1,11)
print ("Random Level: ", end =' ')
print (level)
bonus = 5000.00
while (error):
try:
if (level >=5 and level <=8):
error = False
print ("Expected Bonus: $5,000.00")
print (name + ", your bonus is $", end =' ')
print (bonus)
elif (level <= 4 ):
error = False
bonus = bonus * yearsexp * performance * level
print ("Expected bonus: ", end =' ')
print (bonus)
print (name + ", your bonus is $", end =' ')
print (bonus)
else:
raise ValueError
except:
print ("You do not get a bonus")发布于 2019-10-07 20:29:16
您没有将performanceError设置为False
if (performance <= 11):
expError = False需要更改为
if (performance <= 11):
performanceError= Falsehttps://stackoverflow.com/questions/58276660
复制相似问题