I'm unable to print all the elements of the list in the same line.
For n = 5
, I was expecting the output
1 2 3 4 5
but instead I got
1
2
3
4
5
I'm unable to print all the elements of the list in the same line.
For n = 5
, I was expecting the output
1 2 3 4 5
but instead I got
1
2
3
4
5
This should solve your problem.
n = int(input("Enter the value of n: "))
l = []
for i in range(n):
l.append(i+1)
print("Elements of the list are:", end=" ")
for i in l:
print(i, end=" ")