mardi 28 janvier 2020

How to append an item in a list for use later in a If-statement

I'am creating a text-based game, and I have a problem when I try to add a Knife to pass to the Forest. My idea is that the gamer, need to use the 'C' option to add a Knife to the inventory. And use that Knife to pass to the forest in 'B' option. Any solution please?

a1 = input('What you want to do? \nCheck some rock around you(A) \nGo to the Forest(B) \nSee around of the beach in the island(C) \n\n')
            obj = []
            def addknife():
                obj.append('Knife')
            if a1.capitalize() == 'A':
                print()
                print('It is nothing else than a rock.')
            elif a1.capitalize() == 'C':
                print()
                print('Walking for the beach, you encountered a Knife.')
                addknife()
                print(obj)
            elif a1.capitalize() == 'B':
                if 'Knife' in obj:
                    print('You can go to the forest.')
                else:
                    print('The plants do not allow you to pass.')```

Aucun commentaire:

Enregistrer un commentaire