Reputation: 15
I'm having a problem in the betting part of a blackjack game i am making, i would like the player to be able to bet $0 if they want to, however when you input 0 it simply repeats the input. Please help as this is the last step to a successful game that i have been working on for a while.
money=250
validbet=False
while validbet==False:
bet = None
while not bet:
unchecked_bet = input("How much would you like to bet? $")
try:
bet = float(unchecked_bet)
except ValueError:
print("Sorry, that is not a valid bet. Please enter a valid bet.".format(unchecked_bet))
bet=float(unchecked_bet)
if bet>=0 and bet<=money:
validbet=True
else:
print("Sorry, that is not a valid bet. Please enter a valid bet.")
validbet=False
print("You have bet: $"+str(bet))
Thanks in advance
Upvotes: 0
Views: 92
Reputation: 17877
while not bet
evaluates to False
if bet == 0
. You probably want to check for
while bet is None
to handle None
more explicitly.
Note that bet == None
would work as well. But bet is None
is more precise and the recommended way to check for None
. (See this question for more details.)
Upvotes: 1