我正在做一个价格是正确的游戏。我目前正在开发一个类似于参赛者行列的游戏模式,在那里他们猜测一件物品的价格。你知道吗
当它要求您提交投标时,如果您输入一个单词(而不是投标),程序将崩溃并显示以下错误:
"Traceback (most recent call last): File "C:\Users\alexe\AppData\Local\Programs\Python\Python36\Thepriceisright.py", line 36, in contestantrow() File "C:\Users\alexe\AppData\Local\Programs\Python\Python36\Thepriceisright.py", line 24, in contestantrow protagnum=int(input(propername +", what is your bid?")) ValueError: invalid literal for int() with base 10: 'alexei'"
这是我的密码:
import random
print(" The Price is Sorta Right - 000776331")
welcomeplayer = True
contestantrow = True
def welcome():
while True:
global welcomeplayer
global propername
welcomeplayer = input("Please enter your name using only letters")
validname = welcomeplayer.isalpha()
propername = welcomeplayer.capitalize()
if validname == True:
print( propername, " ! Come on down! You're the next contestant on the Price is (sorta) right")
print (" Dew Drop welcomes " ,propername ," to contestants row joining EIMNOT A. HUMAN,ARTHURFICIAL EINTEL , ROBORT")
return
else:
print("Please only write letters on your name tag")
welcomeplayer = False
def contestantrow():
while True:
print("Dew Drop shows the price that you are bidding on")
protagnum=int(input(propername +", what is your bid?"))
if protagnum > 0:
componebid = random.randint(1,1000)
print("EIMNOT A. HUMAN bids: ",componebid)
comptwobid = random.randint(1,1000)
print("ARTHURFICIAL EINTEL bids: ",comptwobid)
compthreebid =random.randint(1,1000)
print("ROBORT bids: ",compthreebid)
else:
print(" Dew Drop says [Im sorry bids should start at atleast one dollar]")
contestantrow = False
welcome()
contestantrow()
您正在将int/string转换为int。“1”将起作用,但“a”将引发ValueError
相关问题 更多 >
编程相关推荐