0% found this document useful (0 votes)
11 views1 page

Python List Shuffle and Guess Game

The document contains code that defines functions for shuffling a list, getting a player's guess, and checking if the guess is correct. It shuffles a sample list, gets a player guess, and checks if the guess matches the shuffled list, printing the result. An error occurs initially as the shuffle function is not imported, but importing it from the random module resolves the issue.

Uploaded by

Rahul Mehta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views1 page

Python List Shuffle and Guess Game

The document contains code that defines functions for shuffling a list, getting a player's guess, and checking if the guess is correct. It shuffles a sample list, gets a player guess, and checks if the guess matches the shuffled list, printing the result. An error occurs initially as the shuffle function is not imported, but importing it from the random module resolves the issue.

Uploaded by

Rahul Mehta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.

1928 64 bit
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def shuffle_list (mylist):
... shuffle (mylist)
... return mylist
...
>>> mylist = [' ','o',' ']
>>> 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")
... print (mylist)
...
>>> mylist = [' ','o',' ']
>>> mixedup_list = shuffle_list(mylist)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 2, in shuffle_list
NameError: name 'shuffle' is not defined
>>> from random import shuffle
>>> mixedup_list = shuffle_list(mylist)
>>> guess = player_guess()
Pick a number 0,1,20
>>> check_guess(mixedup_list,guess)
correct
>>>

You might also like