14. It's Dangerous to go alone! Take this


#1

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() 

# Your code here
inventory["pocket"] = ["seashell", "strange berry", "lint"]

inventory["backpack"].sort()

inventory["backpack".remove("dagger")

inventory['gold'] += 50

print inventory

What am i doing wrong?

Error Message:

File "python", line 20
inventory['gold'] += 50
^
SyntaxError: invalid syntax


#2

This operation cannot be done the way you are doing it,

What you should do is use an equal sign instead and add 50 to 500 like so,

inventory['gold'] = 500 + 50


#3

the problem is actually here:

inventory["backpack".remove("dagger")

check all your brackets/parentheses in this line.

i disagree with @bandit, you can use += to increase your gold


#4

@bandit thanks for that, but it makes no difference

@stetim94 About which brackets/parentheses do u think? Are the brackets of the backpack at the wrong pos?


#5

don't apply bandit suggestion, your code was fine

i think a ] is missing in the line i told you about


#6

I was saying that in reference to the error he was getting, but I guess the way I said it didn't seem like it


#7

@stetim94 but where? if i do inventory[] it gets an error on that. But everywhere else it gets the error on line 20 again


#8

can i see an updated version of your code?


#9

@stetim94

Your code here

inventory["pocket"] = ["seashell", "strange berry", "lint"]

inventory["backpack".sort()]

inventory['backpack'.remove("dagger")

inventory['gold'] = 500 + 50

print inventory


#10

this line:

inventory['backpack'.remove("dagger")

a ] is still missing, check the line to see all parentheses/square brackets have matching closing and opening

ditch bandit suggestion and go back to inventory['gold'] += 50


#11

Your code here

inventory["pocket"] = ["seashell", "strange berry", "lint"]

inventory["backpack".sort()]

inventory['backpack'.remove("dagger")]

inventory['gold'] = 500 + 50

print inventory

if i have all, i get antopher one

Traceback (most recent call last):
File "python", line 16, in
AttributeError: 'str' object has no attribute 'sort'


#12

okay, i see, you now added the ], but now on both this lines:

inventory["backpack".sort()]

inventory['backpack'.remove("dagger")]

] is at the wrong place.

.sort() and .remove() are both methods for list look:

print [5,4,3,2,1].sort()
print [1,2,3,4,5].remove(1)

see how i call the methods on the list? not inside the list


#13

THANK YOU, now i understand haha


#14