Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List logic
#9
You want your return statement in addToInventory to be at the same indentation level as the for loop. That way, it won't execute until the for loop is completely done. As it is now, it executes each time through the loop, so the first time through the loop, it executes and the function ends.

Note that you don't actually need the return statement. Dictionaries are mutable, so when you change inventory in addToInventory, it's also changing stuff in the main program. Basically, stuff and inventory are pointing to the same dictionary. If your next to last line was just:
addToInventory(stuff, dragonLoot)
then it would work without the return statement in addToInventory.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
List logic - by Low_Ki_ - Apr-22-2017, 02:03 AM
RE: List logic - by Low_Ki_ - Apr-22-2017, 03:08 AM
RE: List logic - by ichabod801 - Apr-22-2017, 10:50 AM
RE: List logic - by Low_Ki_ - Apr-22-2017, 04:56 PM
RE: List logic - by idontreallywolf - Apr-22-2017, 11:10 AM
RE: List logic - by tomhath - Apr-22-2017, 03:41 PM
RE: List logic - by ichabod801 - Apr-22-2017, 05:44 PM
RE: List logic - by Low_Ki_ - Apr-22-2017, 06:53 PM
RE: List logic - by ichabod801 - Apr-22-2017, 09:24 PM
RE: List logic - by Low_Ki_ - Apr-22-2017, 11:46 PM
RE: List logic - by Low_Ki_ - Apr-23-2017, 02:29 AM
RE: List logic - by wavic - Apr-23-2017, 04:21 AM
RE: List logic - by Low_Ki_ - Apr-23-2017, 04:31 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020