Python 错误提示,而不是重新输入输入的提示
我正在做一个价格是正确的游戏。我目前正在开发一种类似于参赛者排的游戏模式,在这种模式下,他们可以猜测物品的价格 当它要求您提交投标时,如果您输入一个单词(而不是投标),程序将崩溃并显示以下错误: “回溯(最近一次呼叫最后一次): 文件“C:\Users\alexe\AppData\Local\Programs\Python\Python36\Thepriceisright.py”,第36行,在 第行() 文件“C:\Users\alexe\AppData\Local\Programs\Python\Python36\Thepriceisright.py”,第24行 protagnum=int(输入(propername+“,您的出价是多少?”) ValueError:基数为10的int()的文本无效:“alexei” 这是我的密码:Python 错误提示,而不是重新输入输入的提示,python,python-3.x,while-loop,python-module,Python,Python 3.x,While Loop,Python Module,我正在做一个价格是正确的游戏。我目前正在开发一种类似于参赛者排的游戏模式,在这种模式下,他们可以猜测物品的价格 当它要求您提交投标时,如果您输入一个单词(而不是投标),程序将崩溃并显示以下错误: “回溯(最近一次呼叫最后一次): 文件“C:\Users\alexe\AppData\Local\Programs\Python\Python36\Thepriceisright.py”,第36行,在 第行() 文件“C:\Users\alexe\AppData\Local\Programs\Pytho
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/字符串转换为int。“1”将起作用,但“a”将引发ValueError
while True:
try:
protagnum=int(input(propername +", what is your bid?"))
break
except ValueError:
print("Invalid bid, please try again")
您正在将int/字符串转换为int。“1”将起作用,但“a”将引发ValueError
while True:
try:
protagnum=int(input(propername +", what is your bid?"))
break
except ValueError:
print("Invalid bid, please try again")
使用该代码块周围的Try/Exception块捕获异常值error并请求另一个输入使用该代码块周围的Try/Exception块捕获异常值error并请求另一个输入我尝试了,当我输入字符串时,出现了一个错误。我保留了if protagnum>0部分,因为出价必须至少为1美元,而且不能是文本。我尝试了一下,当我输入字符串时,出现了一个错误。我保留了if protagnum>0部分,因为出价必须至少为1美元,而且不能是文本。