I'm completing my final project for my first programming course in python using the code below. The majority of this already works. The idea is a text based adventure game where you are meant to collect 6 items before you get to the "boss room." The only thing giving me an issue is in the status function, it's meant to print the players inventory. However, when the player goes to collect the first item it isn't printing Inventory: [Self Portrait] but rather Inventory: ['S', 'e', 'l', 'f', ' ', 'P', 'o', 'r', 't', 'r', 'a', 'i', 't']. Not sure how to fix this even though it might seem like a stupid question, haha, but I'm a beginner so! My full code is below.
def instructions():
print('You are taking part in a museum heist!')
print("Collect all 6 paintings before you find your mafia boss, or you will get fired!")
print("To move, type: North, South, East, or West.")
print("To collect an item, type: Collect")
print('To quit, type Quit')
instructions()
print('----------------------')
def status():
print('You are in the', current_room, 'Room')
print('Inventory:', str(inventory))
if 'item' in rooms[current_room]:
print('You see an artwork called', str(rooms[current_room]['item']))
print('----------------------')
inventory = []#placeholders
item = ' '
def main():
inventory = []
rooms = {
'Foyer': {'East': 'Contemporary'},
'Contemporary': {'North': 'Impressionist', 'East': 'Abstract', 'West': 'Foyer', 'South': 'Surrealist', 'item': 'Self Portrait'},
'Abstract': {'North': 'Pop Art', 'West': 'Contemporary', 'item': 'Convergence'},
'Pop Art': {'South': 'Abstract', 'item': 'Shot Marilyns'},
'Surrealist': {'North': 'Contemporary', 'East': 'Realist', 'item': 'The Persistence of Memory'},
'Impressionist': {'South': 'Contemporary', 'East': 'Expressionist', 'item': 'Poppies'},
'Expressionist': {'West': 'Impressionist', 'item': 'Starry Night'},
'Realist': {'West': 'Surrealist', 'item': 'Mafia Boss'}
}
current_room = 'Foyer'
while True:
status()
if rooms[current_room] == rooms['Realist']:
print('Oh no! Your boss is angry you did not steal all the paintings! You have been fired. GAME OVER.')
break
if len(inventory) == 6:
print('Congratulations! You got all the paintings. You Win!!')
break
print('----------------------')
print('Which way?')
move = input()
if move == 'Quit':
print('Sorry to see you go!')
break
elif move == 'Collect':
if 'item' in rooms[current_room]:
inventory += str(rooms[current_room]['item'])
print("You collected", str(rooms[current_room]['item']))
del rooms[current_room]['item']
else:
print('There is no item here.')
elif move == 'North' or 'South' or 'East' or 'West':
if move in rooms[current_room]:
current_room = rooms[current_room][move]
else:
print("Sorry, you can't go that way.")
move = input()
current_room = current_room
else:
print('Invalid move!')