Python 14/14 GLITCHED?!? (FIXED!)


#1

I know a few of you saw my last question, but I srsly think something is going on with my account for the reason that this code isn't working either. I will leave my code below....

inventory = {
'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'],
'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()

Your code here

inventory['backpack'].sort()
inventory['backpack'].remove('dagger')
inventory['gold'] += 50

Above is my code, I don't see the problem with it. Plz reply as quickly as possible as i am needing assistance before moving on to my next lesson. I appreciate everyone who tries to help, but I am certain its just a glitch (sorry for the freakishly big numbers above...)


#2
inventory = {    'gold' : 500, 
   'pouch' : ['flint', 'twine', 'gemstone'],
    'pocket' : ['seashell', 'strange berry', 'lint']   <==forgetting a comma-, !!!!!!
    'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}

#3

It looks to me like you forgot steps 1 and 2:
01.. Add a key to inventory called 'pocket'
02. Set the value of 'pocket' to be a list consisting of the strings 'seashell', 'strange berry', and 'lint'

Try adding this code to complete those steps:

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

#4

thank you guys, but just as before my computer still seems to not want to accept any of the codes your giving me. I think i have to restart the computer or the code because this isn't the first time its done this. Thank you all! :smile:


#5

Cool. Let me know if it still doesn't work :smiley:


#6

@123jordyn123,
Maybe....
++++ reset of session *****************
under certain circumstances you can shoot your Browser in an
inconsistent state.

Therefor it is of an advantage to know that you have 2 reset facilities:

One is the use of the F5-key which does a refresh Browser

and

Two, select&copy your code
Then use the Reset Code button of the course-window,
then paste your code back in.

Addendum
General Notes:
Always refresh the browser after making corrections:
CTRL f5 ( if on Windows or Linux)
CMD r ( if on a MAC).
CTRL 0 to reset browser zoom


#7

inventory = { 'gold' : 500,
'pouch' : ['flint', 'twine', 'gemstone'],
'pocket' : ['seashell', 'strange berry', 'lint']
'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}

Can anyone tell me what they see wrong with this code? because its not working???


#8

@droughton,

The properties of a dictionary / object
are separated from each other by a comma-,
like

inventory = { 'gold' : 500, 
 'pouch' : ['flint', 'twine', 'gemstone'],
 'pocket' : ['seashell', 'strange berry', 'lint'], #<< separator !!!!
 'backpack' : ['xylophone','dagger', 'bedroll','bread loaf']}

#9

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 = {
'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"] = 550 #can't come with a better version

print inventory

This worked for me


#10

'pocket' : ['seashell', 'strange berry', 'lint'] <--- there should be a comma after this, but you should insert this where you are supposed to write your code not directly in to the inventory


#11

THANKS SO MUCH EVERYONE! The code worked for me. thanks to everyone who helpedz!


#12

inventory["gold"] += 50


#13

can you explain me why there is a "+" sign? I am confused :confused:


#14

the '+' sign is there to add more gold to the player


#15

Oh okay, it makes sense now, we are just adding extra gold to the existing gold. Thanks :smile:


#16

your welcome dataplayer10188


#17

why is it += instead of =+?


#18

@wengjunkai,

It is called SYNTAX, the rules defined for this language.....

google search
== the Book ==
javascript compound operator
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Assignment_operators

Compound assignment operators that are shorthand for the operations listed in the following table:

Compound assignment operators

Name                      Shorthand operator       Meaning
=======================   ===================      ==========
Assignment                        x = y            x = y 
Addition assignment               x += y           x = x + y 
Subtraction assignment            x -= y           x = x - y 
Multiplication assignment         x *= y           x = x * y 
Division assignment               x /= y           x = x / y 
Remainder assignment              x %= y           x = x % y 
Exponentiation assignment         x **= y          x = x ** y 
Left shift assignment             x <<= y          x = x << y 
Right shift assignment            x >>= y          x = x >> y 
Unsigned right shift assignment   x >>>= y         x = x >>> y 
Bitwise AND assignment            x &= y           x = x & y 
Bitwise XOR assignment            x ^= y           x = x ^ y 
Bitwise OR assignment             x |= y           x = x | y

Slide to the Left! Slide to the Right!
#19

So does x <<<= y mean x = <<< y?


#20

works:

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["backpack"].remove("dagger")

inventory['gold'] += 50