0
a = ['hello','chicken','world']

import random

a = random(a)
print (a) #trying to print them in random order.

how would I print them in random order? It gives me a error: "Type Error: 'module' object is not callable". Also would it be possible to print a word from the list and then ask the user what comes next? and check if the user got it right and continue through the whole list.

3 Answers 3

1

it's because your calling random which is a module and not a method. You probably want to call random.choice see random.choice

Sign up to request clarification or add additional context in comments.

Comments

0

Use random.shuffle() to shuffle your list in place. For example

>>> a = ['hello','chicken','world']
>>> import random
>>> a
['hello', 'chicken', 'world']
>>> random.shuffle(a)
>>> a
['chicken', 'world', 'hello']
>>> random.shuffle(a)
>>> a
['hello', 'world', 'chicken']

2 Comments

My programs seems to print 'chicken , 'hello', 'world'. every time i try print (a) it prints the same variable. How would i make it random each time.
@user2980929 This is after you use random.shuffle(a)? Note it shuffles in place, so you don't need to have a = random.shuffle(a) or anything like that.
0
import random 
a = ['hello','chicken','world']

random.shuffle(a)

print "first element is %s" %a[0]
for i in a[1:]:
    guess = str(raw_input("Guess next item:")).strip()
    if guess == i:
        print "Correct"
    else:
        print "Wrong it was: %s" %i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.