我正在尝试检查一些条件的输入,然后将字符串转换为整数,在此之后我想确保整数不是负数,否则提示用户再次输入。它适用于字符串条件,但是当我输入负数时,输入会引发错误“输入预计最多 1 个参数,得到 2”关于如何评估这一点的任何想法? #This compares whether the bet placed is greater than the value in the players chip_balance. It prompts the player for a lower bet if it is of greater value than chip_balance while bet > chip_balance: print('Sorry, you may only bet what you have 0 -', chip_balance) bet = input("Place your bet: ") while bet == '': bet = input("Can't be an empty bet please try again ") while bet.isalpha() or bet == '': bet = input("Must be a numerical value entered \n \n Place You're bet:") bet = int(bet) if bet < 0: bet = input("Sorry, you may only bet what you have sir! 0 \-", chip_balance) bet = int(bet)
2 回答
拉丁的传说
TA贡献1789条经验 获得超8个赞
bet = input("Sorry, you may only bet what you have sir! 0 \-", chip_balance)
input 函数不接受 2 个参数,而 print 接受。你可以这样做;
bet = input("Sorry, you may only bet what you have sir! 0 \- {}".format(chip_balance))
添加回答
举报
0/150
提交
取消