我正在嘗試檢查一些條件的輸入,然后將字符串轉換為整數,在此之后我想確保整數不是負數,否則提示用戶再次輸入。它適用于字符串條件,但是當我輸入負數時,輸入會引發錯誤“輸入預計最多 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
提交
取消