Home > database >  Assigning value of element to the variable output
Assigning value of element to the variable output

Time:11-17

So, I'm on a beginner's python course on coursera and there is a question I just don't understand:

Assign the value of the 34th element of lst to the variable output.

Here is the list:

1st = ["hi", "morning", "dog", "506", "caterpillar", "balloons", 106, "yo-yo", "python",
       "moon", "water", "sleepy", "daffy", 45, "donald", "whiteboard", "glasses",
       "markers", "couches", "butterfly", "100", "magazine", "door", "picture", "window",
       ["Olympics", "handle"], "chair", "pages", "readings", "burger", "juggle", "craft",
       ["store", "poster", "board"], "laptop", "computer", "plates", "hotdog", "salad",
       "backpack", "zipper", "ring", "watch", "finger", "bags", "boxes", "pods", "peas",
       "apples", "horse", "guinea pig", "bowl", "EECS"]

What am I supposed to do with this thing? I'm not looking for anyone to straight up give me the answer, but rather help me understand what the question wants from me and how to solve it.

CodePudding user response:

output = 1st[34]

"So this is what it says,by indexing the list, you get the value and assign it to the variable output"

CodePudding user response:

To index a list, the correct syntax is:

list[i] where the i is the index of the element you want to retrieve. So in your case:

output = 1st[34]

Good luck with Corsera!

  • Related