亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python中處理負整數的問題

Python中處理負整數的問題

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


查看完整回答
反對 回復 2021-06-08
  • 2 回答
  • 0 關注
  • 244 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號