This forum is now read-only. Please use our new forums! Go to forums

0 points
over 10 years

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.

Answer 5272b410abf8217aaf000678

-6 votes

Permalink

the syntax error is your own, you are missing a comma

the default code passes because the validator crashes, they decided crashing validators should pass so.. <.< i’m reporting it

points
Submitted by Jonatan
over 10 years

1 comments

Thanks for the explanation, that one was really confusing.