Member Avatar for leegeorg07

i have this code:

import random
choices = ['closet', 'lampshade', 'fridge']
print "i have hidden 10,000,000 pounds in one of these places:", choices
choice = raw_input("Where do you want to search? ('closet', 'lampshade', 'fridge')")
random_c = random.choice(choices)
while choice != random_c:
	choices.del(random_c)
	for word in choices:
		if choice == word:
			print word, "is not where it is hidden"
	choice = raw_input("where do you want to search?", choices)
print choice, "is where it is hidden well done"

but whenever i run it it comes it with this error:

> "C:\Python25\pythonw.exe" -u "C:\Python25\word_based game 1.py" 
  File "C:\Python25\word_based game 1.py", line 9
    choices.del(random_c)
              ^
SyntaxError: invalid syntax

Recommended Answers

All 2 Replies

del is a command not a method:

del lst[index]

You can also do:

lst.remove(item)

and

removed = lst.pop(index)

The second seems to be the one you want.

Member Avatar for leegeorg07

first off i wanna say sorry for blowing off before i just couldn't understand how you didn't understand why we wanted to find out
yeah thanks i realised that after i published it, i now have:

import random
choices = ['closet', 'lampshade', 'fridge']
print "i have hidden 10,000,000 pounds in one of these places:", choices
choice = raw_input("Where do you want to search? ('closet', 'lampshade', 'fridge')")
random_c = random.choice(choices)
while choice != random_c:
	choices.remove(choice)
	print choice, "is not where it is hidden"
	print "where do you want to search?"
	choice = raw_input(choices)
print choice, "is where it is hidden well done"

how can i expand this.

commented: No hard feelings +5
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.