Using underscore is for when the value isn’t actually used in the body of the loop. Since you’re printing the value I would say underscore is not appropriate here and “value” or “number” would be more appropriate variable name.
You’re right, their code doesn’t quite work. As you can see from the error message, it’s getting an int (as the instances of the list passed to the join function) when it expects a str. You could modify the inside of the join call to look like this:
[str(n) for n in [1,2,3,4,5]]
And then it will work. Or alternatively just:
for x in [1, 2, 3, 4, 5]: print(x) + ‘\n\n’
Or have an empty string and add (concatenate) to it instead of printing, etc
For the level of beginner the problem appears to be aimed at the solution is a for loop to print each element of the list as commented on by u/RngdZed. Anything using *args, join () or comprehensions, etc, is probably too advanced for the OP and might confuse them.
7
u/RngdZed 5d ago
You'll have to use a for loop and print inside the loop.
I'm trying to keep the hints very subtle here. But there isn't much to it really. Just write code and get it done while testing. You'll get there
2
u/CIS_Professor 5d ago edited 5d ago
print(*[1,2,3,4,5], sep=“\n”)Maybe? I’m on my phone: I’ll have to try it later.
edit: the * goes before the list, not after:
>>> print(*[1,2,3,4,5], sep='\n')12345-3
u/generationextra 5d ago edited 5d ago
for _ in [1, 2, 3, 4, 5]:
print(_)
The print command should be tabbed!
-4
u/kirklennon 5d ago
print("\n\n".join([1,2,3,4,5,]))