i have already read all the other slot machine post, and i can understand the theory of the loop and get all the other solutions, until the code is simple and short.
my array is so bad at the moment that i can't really figure out why i can't play more than one time
here my entire array, it include the help came for other questions i have opened in the past 2 days.
please be sincere and rude if this code sucks:
import random
import time
cr = 100
print('[- play simple slot machine game -]')
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print('[- start at ' + str(cr) + 'cr place your bet -]')
time.sleep(1)
slot = []
for row in range(9):
slot.append([None] * 9)
def print_slot(slot, empty='[ ]'):
for row in slot:
print(' '.join(empty if element is None else '{{: ^{}}}'.format(len(empty)).format(element) for element in row))
print_slot(slot)
time.sleep(1)
print('[- play simple slot machine game -]')
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
def game_start():
cr = 100
bet = int(input('[- digit the num of coins to bet -] \n '))
if (cr > 0) and (0 < bet <= cr):
cr = 100 - bet
first_n = random.randint(0, 9)
second_n = random.randint(0, 9)
third_n = random.randint(0, 9)
fourth_n = random.randint(0, 9)
fifth_n = random.randint(0, 9)
slot[4][2] = str(first_n)
slot[4][3] = str(second_n)
slot[4][4] = str(third_n)
slot[4][5] = str(fourth_n)
slot[4][6] = str(fifth_n)
if first_n == second_n and second_n == third_n and third_n == fourth_n and fourth_n == fifth_n:
cr += bet * 100
time.sleep(1)
print('[- play simple slot machine game -]')
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print_slot(slot)
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print('[- you won!!! now you have ' + str(cr) + 'cr -]')
bet = int(input('[- digit the num of coins to bet -] \n '))
return bet
else:
time.sleep(1)
print('[- play simple slot machine game -]')
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print_slot(slot)
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print('[- you loose! now you have ' + str(cr) + 'cr -]')
bet = int(input('[- digit the num of coins to bet -] \n '))
return bet
elif cr < 0:
time.sleep(1)
print('[- play simple slot machine game -]')
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print_slot(slot)
time.sleep(1)
print('[- with five identical n you win -]')
time.sleep(1)
print('[- you ran out of money 2 bet :( -]')
game_start()
You have to
-=
the credit each time there is a bet and just remove the elif, I removed some unnecessary lines, added atry/except
to cast to an int and catch bad input and a way for the user to quit the game. You can add a sleep or two where you like but it should run how you want:cr = 100 - bet
keeps setting cr - equal to 100 - the current bet, it does not update the cr by decrementing by the bet amount.Having a
return bet
in your code will cause the function to end when you reach that statement no matter how much credit you have, you only want to break/return when you have 0 dollars left or the user wants to leave.