Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
if i want it to output 4 values on every line:
example: for in range(12):
print(i,end=' ')
this will print on one line but how can i let the python jump to the next line after the 4th output?

What I have tried:

i tried minimizing the idle screen
Posted
Updated 21-Mar-16 23:01pm
v2

Python won't do this for you. You have to print each value, one at a time, yourself. Each time you print a value you increment a counter. When that counter reaches 4, go to the next line and reset the counter.
 
Share this answer
 
Python
for x in range(1,13,4):
    for y in range(x, x+4):
        print(y, end=", ")
    print("")


[edit]
A slightly neater version:
Python
for x in range(1,13,4):
    for y in range(x, x+3):
        print(y, end=", ")
    print(y+1)

[/edit]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900