0
from random import shuffle

mylist = [' ','O',' ']

my_new_list = shuffle_list(mylist)

guess = player_guess

check_guess(my_new_list,guess)

def shuffle_list(list):
    shuffle(list)
    return list

def player_guess():
    
    guess = ''
    while guess not in ['0','1','2']:
        guess = input("pick a number: 0 , 1 , 2")
    return int(guess)

def check_guess(mylist,guess):
    if mylist[guess] == 'O':
        print("Correct!")
    else:
        print("Wrong guess!")
        print(mylist)

I receive this error

NameError                                 Traceback (most recent call last)
Input In [2], in <cell line: 5>()
      1 from random import shuffle
      3 mylist = [' ','O',' ']
----> 5 my_new_list = shuffle_list(mylist)
      7 guess = player_guess
      9 check_guess(my_new_list,guess)

NameError: name 'shuffle_list' is not defined
Jab
  • 26,853
  • 21
  • 75
  • 114

1 Answers1

0

Python reads scripts from top to bottom, so when it reaches the line where you call shuffle_list python doesn't yet know what shuffle_list is and so it throws an exception. All you need to do to fix it is to move the lines with function calls to the bottom.

from random import shuffle

mylist = [' ','O',' ']

def shuffle_list(list):
    shuffle(list)
    return list

def player_guess():
    
    guess = ''
    while guess not in ['0','1','2']:
        guess = input("pick a number: 0 , 1 , 2")
    return int(guess)

def check_guess(mylist,guess):
    if mylist[guess] == 'O':
        print("Correct!")
    else:
        print("Wrong guess!")
        print(mylist)

# All of the code below can't run until the functions have been defined 

my_new_list = shuffle_list(mylist)
guess = player_guess   # You probably want to call this e.g. player_guess()
check_guess(my_new_list,guess)

Alexander
  • 16,091
  • 5
  • 13
  • 29