Why there is typeerror? | Sololearn: Learn to code for FREE!

0

Why there is typeerror?

rnglst=list(range(1,101)) for a , b , c ,d in rnglst: Print(a) Print(b) Print(c) Print(d) https://code.sololearn.com/c1rbKFWhEJk6/?ref=app

4/11/2021 8:26:23 AM

MsM!67

6 Answers

New Answer

0

Ah, I think now I have some more clue, on what is the problem. But to be honest, I didnt really understand your code... But maybe this code bit helps a little on the Overall issue: https://code.sololearn.com/cqdFxQ8f15MO/?ref=app

+2

MsM!67 You missed ) after list Also you cannot iterate list like that.

0

Thanks for pointing that missed bracket but I had posted the question because of typeerror which is raised due to this for statement Hoping to get the answer soon

0

As 🅰🅹 (Challenge Accepted) mentioned, it is not allowed to iterate on a list like this. If you want to print the first 4 members of the list, try this: rnglst=list(range(1,101)) for num in rnglst[:4]: print(num) In this for loop you go through every Element of the list. On each Iteration, the current Element is represents as num, in this example. [:4] defines the "Limits" for the Iteration. It is similar to [0:4], while 0 Can be omitted. It means, to use a slice of the list from Element 0 to Element 3, in other words -> [startIndex : endIndex], while endIndex is exclusive, so the last Element is endIndex - 1.

0

Thanks but might I am not able to explain the problem so would you please check out my code and then please suggest some nonintutive /intuitive or a correct way to iterate through that list. Please suggest me a way to do that using a for loop if possible.

0

Thanks That was great!