#FIRST tourial

36 messages · Page 1 of 1 (latest)

prime tiger
#

it said its not defined but i define everythinhg

#

import random

MAX_LINES=3
MAX_BET= 1000
MIN_BET= 1

ROWS=3
COLS=3

Symbol = {
"A":2,
"B":4,
"C":6,
"D":8
}

def get_slot_machine_spins(ROW,COl,Symbol):

all_symbols=[]
for Symbol,symbol_count in Symbol.items():
for _ in range(symbol_count):
all_symbols.append(Symbol)

     columns= []
     for COL in range(COLS):
          column= []  
          current_symbols=all_symbols[:]
          for ROW in range(ROWS):
              value= random.choice(current_symbols)
              current_symbols.remove(value)
              column.append(value)

              columns.append(column)

return columns

def print_slot_machine(columns):
for ROW in range(len(columns[0])):
for i, column in enumerate(columns):
if i != len(columns):
print(column[ROW], end=" | ")
else:
print (column[ROW])

        print()
#

def deposit():
while True:
amount=input("Enter amount to deposit: $")
if amount.isdigit():
amount=int(amount)
if amount>0:
break
else:
print("enter amount must be greater than 0")
else:
print("Please enter a positive number")
return amount

def get_numbers_of_lines():
while True:
lines = input("Enter Number of lines to bet on (1-"+ str(MAX_LINES)+")? ")
if lines.isdigit():
lines = int(lines)
if 1 <= lines <= MAX_LINES:
break
else:
print("enter amount must be greater than 0")
else:
print("Please entdeposit()er a positive number")

return lines

get_numbers_of_lines()

def get_bet():
while True:
amount=input("Enter amount to bet: $")
if amount.isdigit():
amount=int(amount)
if MIN_BET<= amount <= MAX_BET:
break
else:
print(F"enter amount must be between ${MIN_BET} -${MAX_BET} ")
else:
print("Please enter a positive number")
return amount

slots= get_slot_machine_spins(ROWS, COLS,Symbol)

print_slot_machine

def main():
balance=deposit()
lines = get_numbers_of_lines()
while True:
bet= get_bet()
total_bet= bet*lines
print(f"you are betting ${bet} on {lines} lines. total is equal to: ${total_bet}")
print(balance,lines)
main()

hollow tigerBOT
#

cowboy W7HCC
Compile Error! Click the errors reaction for more information.
(You may edit your message to recompile.)

worldly dock
#

I'd say the issue is here

#
   for Symbol,symbol_count in Symbol.items():
      for _ in range(symbol_count):
         all_symbols.append(Symbol)

         columns= []
         for COL in range(COLS):
              column= []  
              current_symbols=all_symbols[:]
              for ROW in range(ROWS):
                  value= random.choice(current_symbols)
                  current_symbols.remove(value)
                  column.append(value)

                  columns.append(column)
#

the error is telling you that the variable current_symbol is empty

#

so random.choice can't pick from an empty list

#

One of the issues here is that you're overwriting the global variable Symbol in the for loop

#

basically when you iterate you assign anew value to Symbol

prime tiger
#

like this?

worldly dock
#

current_symbols=all_symbols[:] this line is fine. This basically makes a copy of a list current_symbols. You have to do this so you're not changing the list all_symbols

#

for Symbol,symbol_count in Symbol.items():
so the original variable

Symbol = {
   "A":2,
   "B":4,
   "C":6,
   "D":8
}

that you pass to the function in line 89
gets called here with Symbol.items().

But with for Symbol, symbol_count... you assign a new value to the variable Symbol. So you would have to change it to something like this so you maintain the original value of the the variable
for sym, symbol_count in Symbol.items():

and because you renamed the variable you're looping through you also have to change this line
all_symbols.append(Symbol)

prime tiger
#

so line 27 is good?

worldly dock
prime tiger
#

then i dont understand what i need to do

prime tiger
#

sorry

worldly dock
#

20: for sym, symbol_count in Symbol.items():

22: all_symbols.append(sym)

prime tiger
#

ok

worldly dock
prime tiger
#

update

worldly dock
#

and I am guessing you deleted the definition of all_symbols?

prime tiger
#

must have

prime tiger
worldly dock
prime tiger
#

so i add for Symbol,symbol_count in Symbol.items():
?`

worldly dock
#

now change it to
for sym,symbol_count in Symbol.items():

prime tiger
#

ok

prime tiger
#

it worked

worldly dock