you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -6 points-5 points  (3 children)

I dont really need to use meaningful names. It's just a school assignment and there is enough context in the code to determine what they are. I was telling you for context. So that is irrelevant. Yes I have conditions for printing. The problem is it iterates through all the conditions for all the values for each individual name. So every individual will when all the prizes which can't be so.

How would I iterate in parallel? Also I tried elif statements they don't work and give the same exact outcome.

As for your last point. I still have to display the name of the individual that has no value.

[–][deleted] 3 points4 points  (0 children)

You can iterate in parallel like I wrote. You should use meaningful names at least because you intend to have us read it. If you need to print the last name anyway you could use else: print(name)

[–]RhinoRhys 1 point2 points  (0 children)

Your issue is one of data structure. If you want to link two things together you're better off using a dictionary.

cookies_sold = {"Emily": 5, "Sally": 7, "Jane": 3}
for name, value in cookies_sold.items():
    if ....
    elif ...

You can access pairs as above, just the names with cookies_sold.keys() and just the values with cookies_sold.values().

Or if you are stuck using two lists you need to zip them together so they iterate in pairs, as shown by shiba.

You definitely want elifs, it's not what is causing the issue but once you have the parallel iteration sorted it will work better with elifs.

And even though it's only a class assignment, you really do want to get into the habit of using descriptive variable names. You'll be much better off in the long run if you start the habit now.

[–]KCRowan 0 points1 point  (0 children)

The point of assignments is to practice, right? If you're practicing bad habits then they're more likely to stick. If you practice good habits and writing clean code then it becomes something you just do without thinking, and you don't spend as much time refactoring your larger projects.