Incomplete dice game function, dunno why does'nt works...
If you're not using windows, change the dir. "C:/"
def bet(Bet):
try:
f = open('C:/money.txt')
print f
money = f.readline()
f.close()
print ('You have', money, 'Dollars. Wanna play dice(y/n)?')
v = raw_input()
if v == 'y':
# here i'm printing those values because they seem to be bugged when "money = money - Bet", but not in print Bet or print Money
print money
print Bet
money = money - Bet
dice = random.randrange(1,7)
if dice == 6:
money = money + (Bet * 5)
print '6! Yey! You have', money, 'Dollars'
else:
print 'Damm, a', dice, '!', 'Yo have now', money, 'dollars.'
pass
else:
pass
except IOError:
money = 1000
file = open('c:/money.txt', 'w')
file.write ('1000')
file.close()
bet(Bet)
It reports:
>>> bet(10)
<open file 'C:/money.txt', mode 'r' at 0x015A4340>
('You have', '1000', 'Dollars. Wanna play dice(y/n)?')
y
1000
10
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
bet(10)
File "C:/Documents and Settings/Terminal/Desktop/dado_english.py", line 13, in bet
money = money - Bet
TypeError: unsupported operand type(s) for -: 'str' and 'int'
>>>