You will have to identify the global variables, bet et al. Otherwise, you will be using a second block of memory that is also named bet but local to the function.
if bet == "quit":
break
elif float(bet) <= 0 or float(bet) > x:
print "Invalid bet."
else:
print x, "is a valid amount to bet"
## This would also work
bet_loop=1
break
This works much better as a class.
class Betting:
def __init__(self):
self.bank = 500.00
self.bet = 0.00
# defines the betting process within the program
def bet1(self):
#set bet loop
bet_loop=0
#loop the bet process until the bet is valid
while bet_loop == 0:
#tell how much money you have
print "You have", self.bank, "dollars in the bank, how much do you bet?"
#input b
self.bet = raw_input("Wager?")
#test to make sure that b and x stayed (i did this because it won't work.)
print "self.bet in class =", self.bet
print "self.bank in class=", self.bank
#checks to see if your bet is valid
if self.bet == "quit":
break
elif float(self.bet) <= 0 or float(self.bet) > self.bank:
print "Invalid bet."
else:
print self.bet, "is a valid amount to bet"
print "if you win you will have %7.2f dollars" % (float(self.bet) +self.bank)
## bet_loop=1 ## another option
break
##=====================================================================
if __name__ == "__main__":
## create an instance of the class
BB=Betting() ## or instantiate the class (an awful word)
## when you destroy the class do you outstantiate?
BB.bet1() ## run this function in the class
#another …