If statement not working

I have pasted just a snippet of a code I am working on and struggling with.

The if statement (yes) works just fine but the elif and the else don’t have any errors or do anything and I don’t understand why. Please help.

    while current_room == 'Bathroom':
        if 'Lavender Oil,' not in inventory:
            print('Wow, this bathroom has so many bottles of stuff!')
            print('Do you want to investigate the shelf of bottles?')
            if input().strip().lower() == 'yes':
                print('yes')
            elif input().strip().lower() == 'no':
                print('no')
            else:
                print('else')

Should there be a comma in that string?

1 Like

I’m sure there is a better way to do it but I can’t figure out how to separate my list items other than doing it that way.

1 Like

Can you please show us your original list?

1 Like

The list is created as items are picked up by the player, so the original list is empty until list.append() is used later. I have to create a text-based game for class.

1 Like

If we are constructing a list of strings, then the append method will insert the comma separator. They will not be inside the string.

1 Like

Once I unpack the list though to show the player what is in the inventory there is no longer a comma operator, unless I am doing something wrong. Which is very possible

1 Like

Your if statement has a string literal in the condition. Remove the comma so there is a better chance of matching the string in your list. Is the user meant to capitalize their input? Perhaps confine everything to lowercase.

1 Like

So I changed the code to this (below) and it works now, thank you for trying to help though! I appreciate it!

    while current_room == 'Bathroom':
        if 'Lavender Oil,' not in inventory:
            print('Wow, this bathroom has so many bottles of stuff!')
            print('Do you want to investigate the shelf of bottles?')

            cmd = input().strip().lower()
            if cmd == 'yes':
                print('yes')
            elif cmd == 'no':
                print('no')
            else:
                print('else')
1 Like