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

Time:09-06

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()

CodePudding user response:

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)

CodePudding user response:

  1. if 'bedside' in search: def bedside(): pass bedside() search=input("Where do you want to search next?") if 'wardrobe' in search: //do some code here elif 'desk' in search: //do some code here

    This is the basic gist behind the question you have asked above, sorry for the indentation issues if any since I had to type it directly, thanks:)

  • Related