As I’m sure you’ve found out by now, it looks like you missed the line of code which assures that every item/base in bases gets raised by every power/item in powers.
It may look something like this:
“for n in range(1, len(bases)**2):”
It’s your most outer layer of your nested loops, that tells your function how many list items should be present in your new list.
Also i would set a variable to append instead of the expression (in your 5th line)
If may look something like this:
ex = i**y
empty.append(ex)
return empty
I’m really having a hard time with lists. I dont understand how you can access 2 list and pull one element from one and then make it interact with another one. I’m trying to figure it out by myself, but I could use some help.
Here is where pencil and paper are invaluable. It allows us to sketch and visualize.
Write two lists (five items is enough in each) side by side on a piece of paper. Do this before reading the next instruction.
Ask yourself, do these lists have any relation to each other? The answer to that would suggest pairing, if yes. Otherwise a relation can be defined simply by creating connections.
The exercise relates two lists that are not related in any way. Still, we create a relation by pairing every value in one list with every value in the other list then pass those pairs to the same function and accumulate those results.
That’s where the nested loops are employed. In order to create the complete set of paired values, we need to iterate through one list, and pair each value with every value in the other list. That’s why we iterate the second list each time.
In order to be able to test it would help to have a link to this exercise. Please post it in your reply. Thanks.
D’oh! Link at top of thread. Please belay.
There is more to come, and some of it will seem easier, but, work with this first until you have firm grasp. Nobody is pushing you to the next exercise. We want you to have a full and complete understanding before going ahead. It’s for your benefit, not ours.
Yes, I’m trying to really grasp the concepts and not take the easy way out. So far I understand, a nested for loop is the way to go. The first for loop will go through the lists, the second one to the individual elements in those lists.
What I can’t grasp Is how to relate the len of the second list to just an individual element of the first list, and the move on to the second element and so on.
Ok now this is interesting. I tried changing the code, i think i almost got it, but I’m still not quite getting there, take a look. What an I missing here?