beginner python text game, how do I remove a location from a list that has already been used

Viewed 35

How can I get the user to search one area and then be asked if they want to search the others without the already searched location in the list. Eg:

where do you want to search? x,y,z
x
where else do you want to search? y,z
search=input('Where do you search first?\nBedside table\nWardrobe\nDesk').lower()
   if 'bedside' in search:
       def bedside():
           pass
       bedside()
   if 'wardrobe' in search:
       def wardrobe():
           pass
       wardrobe()
   if 'desk' in search:
       def desk():
           pass
       desk()
2 Answers

You can maintain a list of locations to search in your code, and simply call list.remove(item) to remove the item once it has been input.

eg:

locations = [Bedside, Desk, Wardrobe]

search=input(f'Where do you search first? {locations}').lower()

if search in location:
   location.remove(search)

You'll have to track the options somehow.

One approach might be to list out the options in an array, and remove elements from the array as they are selected. See example:

options = ['Bedside table', 'Wardrobe', 'Desk']
prompt = "Where would you like to search? "

search = input(prompt + ', '.join(options) + ": ").lower()

if 'bedside' in search:
        #do bedside stuff
        options.remove('Bedside table')

search = input(prompt + ', '.join(options) + ": ").lower()
Related