I get
TypeError: Can't convert 'float' object to str implicitly
using
Gambler.pot += round(self.bet + self.money * 0.1)
where the bank, rate and money are all doubled (or at least should be). I'm not sure if this is another Eclipse thing, but how do I get the string to compile?
Code, where bet, and moneyare initialized:
class Gambler:
money = 0
bet = 0
Test case:
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)))
Exiting the test case:
Here, the number is a <class 'int'>
Enter in something: 1
But now, it has turned into a <class 'str'>
Apparently input () changes it to a string.
EDIT : finally fixed the problem (I think) with
self.bet = int(self.bet.strip())
after the user enters a value. Although I do not know if this is the best way to fix the problem :)
Best Daniel G Solution:
self.bet = float(input("How much would you like to bet? $"))
source
share