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

11th Apr 2021, 8:26 AM
MsM!67
6 Answers
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
11th Apr 2021, 1:25 PM
G B
G B - avatar
+ 2
MsM!67 You missed ) after list Also you cannot iterate list like that.
11th Apr 2021, 8:39 AM
A͢J
A͢J - avatar
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
11th Apr 2021, 9:11 AM
MsM!67
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.
11th Apr 2021, 10:28 AM
G B
G B - avatar
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.
11th Apr 2021, 11:08 AM
MsM!67
0
Thanks That was great!
12th Apr 2021, 9:50 AM
MsM!67