This forum is now read-only. Please use our new forums! Go to forums
There is a syntax error in the code made by the course author. What's going on?
(I have screenshots, but I can’t upload them for some reason)
The error in the console:
File “python”, line 4 ‘backpack’ : [‘xylophone’,’dagger’, ‘bedroll’, ‘bread loaf’]} ^ SyntaxError: invalid syntax
The error in the dialogue box:
Oops, try again! Your code looks a bit off. Check the Hint if you need help! Your code threw the following error: invalid syntax (python, line 4)
My code:
inventory = {'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to
"pocket" : ["seashell", "strange berry", "lint"]
'backpack' : ['xylophone','dagger', 'bedroll', 'bread loaf']}
# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']
# Sorting the list found under the key 'pouch'
inventory['pouch'].sort()
# Here the dictionary access expression takes the place of a list name
# Your code here
inventory["backpack"].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] = inventory['gold'] + 50
The original code (as placed by the code author):
inventory = {'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'], # Assigned a new list to 'pouch' key
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}
# Adding a key 'burlap bag' and assigning a list to it
inventory['burlap bag'] = ['apple', 'small ruby', 'three-toed sloth']
# Sorting the list found under the key 'pouch'
inventory['pouch'].sort()
# Here the dictionary access expression takes the place of a list name
Which, for some stupid reason, passes the course by itself. Can anyone explain? Thanks.
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
Thanks for the explanation, that one was really confusing.