0
#I just have these up here for context
def ifhealthlessthan50():

    while health<=50:

        choice2 = input("YOU ARE LOW ON HEALTH WHAT WOULD YOU LIKE TO DO?\n> ")

        if choice2.lower() == 'move n':
            print(random.choice(biomes),  "IS WHERE YOU END UP")

        elif choice2.lower() == 'move s':
            print("pls ")
            print(random.choice(biomes), "IS WHERE YOU END UP")

        elif choice2.lower() == 'move e':
            print("are")
            print(random.choice(biomes), "IS WHERE YOU END UP")

        elif choice2.lower() == 'move w':
            print("gosh")
            print(random.choice(biomes), "IS WHERE YOU END UP")

        elif choice2.lower() == 'exit':
            print("NOW EXITING...")
            sys.exit()

        elif choice2.lower() == 'inventory':
            print(things)

        elif choice2.lower() == 'craft':
            craftinginput = input("WHAT WOULD YOU LIKE TO CRAFT?\n> ")
            if craftinginput.lower() == 'wpickaxe':
                things.remove('PLANKS')
                things.remove('PLANKS')
                things.remove('PLANKS')
                things.remove('STICKS')
                things.remove('STICKS')
            elif craftinginput.lower() == 'wsword':
                things.remove('PLANKS')
                things.remove('PLANKS')
                things.remove('STICKS')

            elif craftinginput.lower() == 'wshovel':
                if 'PLANKS' and 'STICKS' and 'STICKS' not in things:
                    print("YOU DON'T HAVE THE RIGHT MATERIALS!")

                elif 'PLANKS' and 'STICKS' and 'STICKS' in things:
                    things.remove('PLANKS')
                    things.remove('STICKS')
                    things.remove('STICKS')

                else:
                    print("YOU DON'T HAVE THE RIGHT/ENOUGH MATERIALS!")

            else:
                print("THAT'S NOT A CRAFTABLE ITEM!")



        else:
            print("dont work lmao")
            ifhealthlessthan50()
ifhealthlessthan50()

I'm trying to make it so when I don't have all of the materials it displays YOU DON'T HAVE THE RIGHT/ENOUGH MATERIALS! But instead, I get this error this is just one of the functions (the only one where the problem is) I'm really not sure how to fix this, I've looked at many posts here.

ValueError: list.remove(x): x not in list

1 Answers1

0

I believe you have a logic error and these lines are causing your problem:

if 'PLANKS' and 'STICKS' and 'STICKS' not in things:

elif 'PLANKS' and 'STICKS' and 'STICKS' in things:

You need to check if each item is in things individually. Currently, you're only checking if the last item is in things. Consider this example:

things = ['STICKS']
print('PLANKS' and 'STICKS' in things)  # True

'PLANKS' on its own evaluates to True, so only the last string is being checked for in the things array. Checking to see if an item is in the array multiple times is another issue; I'd recommend turning your things array into a dictionary.

Matt
  • 97
  • 1
  • 7