the code is for picking up a key fragment then allowing the player to move on to other rooms but keeps looping while it resets the inventory.
while current_room == rooms['Bathroom']:
print(current_room)
if 'Key Fragment 1' not in inventory:#loop starts here
print('You see the shine of an object')
answer = input('do you want to inspect it? Yes? No?')
if answer.lower() == 'yes' or 'y':
print('its a key fragment')
answer = input('Do you take it? Yes? No?')
if answer.lower() == 'yes' or 'y':
print('You have taken the key fragment')
inventory.append('Key Fragment 1')
print(inventory) #where the loop is supposed to end but resets
else:
print('You left the key fragment')
else:
print('You decided to leave the mysterious object alone')
if 'Key fragment 1' in inventory: #occurs after the loop ends on the collection of items
print(inventory)
print('There are two doors')
print('The first is the door to the entrance hall')
print('The other goes to a bedroom')
answer = input('Do you want to go to the bedroom or the entrance hall?')
if answer.lower() == 'bedroom':
current_room = rooms['Bedroom']
elif answer.lower() == 'entrance' or 'entrance hall':
current_room = rooms['Entrance Hall']
I have the room forced to the bathroom so this code starts but it always loops after getting the item and resets the whole room and inventory before picking up the item? how do I fix this? The code to get into the room works just fine but it doesn't continue after the item is taken. I am new to coding so I'm learning as I fix and debug the code.