Home > front end >  How can I change my output Vertical to Horizontal
How can I change my output Vertical to Horizontal

Time:07-08

I want to make my output like this

1 2 3 4 5 6 7 8 9 10

What change need for this program. Make my output in Vertical to Horizontal

Program

 i = 1
    while i<=10 :
      print(i)
      i= i 1

Output

1
2
3
4
5
6
7
8
9
10

# I want to make my output like this 
1 2 3 4 5 6 7 8 9 10 

CodePudding user response:

You need to change your code like this:

i = 1
while i<=10 :
    print(i, end=' ')
    i= i 1
print()

Output:

1 2 3 4 5 6 7 8 9 10 

CodePudding user response:

You can do it without while-loop if you already have your list:

>>> lst
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> print(*lst)
1 2 3 4 5 6 7 8 9 10

Or you still like to loop it, but don't want to count:

for n in lst:
    print(n, end=' ')

    
1 2 3 4 5 6 7 8 9 10 
  • Related