TypeError: Can't convert 'float' object to str implicitly
同時使用
Gambler.pot += round(self.bet + self.money * 0.1)
哪裏鍋,賭,和金錢都是雙打(或至少應該是)。我不確定這是不是另一個Eclipse的東西,但我如何獲得編譯的線?
其中bet
和money
被初始化代碼:
class Gambler:
money = 0
bet = 0
測試用例:
number = 0
print("Here, the number is a {0}".format(type(number)))
number = input("Enter in something: ")
print("But now, it has turned into a {0}".format(type(number)))
從測試情況下的輸出:
Here, the number is a <class 'int'>
Enter in something: 1
But now, it has turned into a <class 'str'>
顯然,輸入()被其更改爲一個字符串。
EDIT:與
self.bet = int(self.bet.strip())
最後固定的問題(我認爲)用戶輸入值之後。雖然我不知道,如果這對解決問題:)
由丹尼爾·摹:更好的解決方案
self.bet = float(input("How much would you like to bet? $"))
請顯示self.bet和self.money初始化的代碼。 – GreenMatt 2010-03-21 01:47:46
你還沒有證明這些不是字符串。 – 2010-03-21 01:48:14
這就夠了,還是我應該發佈更多的代碼? – wrongusername 2010-03-21 01:48:47