-3

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
wovano
  • 4,543
  • 5
  • 22
  • 49

1 Answers1

0

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=" ")