Python Forum
Thread Rating:
  • 2 Vote(s) - 1.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List logic
#10
(Apr-22-2017, 09:24 PM)ichabod801 Wrote: 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.

Ok so that worked perfectly, I took out the return statement and changed the 18th line to what you said. It worked great. Thank you very much. I do apologize I'm trying to practice with lists and dicts because i'm real terrible with them. I am getting better with the basic concepts and logics in python but lists and dicts are more difficult... Like my first question about drawing the heart... I know the logic but I have no clue how to write it. Lol.

I wish I could find some kind of worksheets to do with basic terms in python. Like online workshops or something to grade efficiency and terminology used.
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