Hello, I'm a beginner at Python.
a=10
b=7
c=5
d=9
e=8
f=2
print(a,b,c,d,e,f)
>>> 10 7 5 9 8 2
How do I print out by breaking it into multiple lines?
10 7 5
9 8 2
3 lines per line, 2 lines in total, or
10 7
5 9
8 2
2 lines per line, 3 lines in total, etc.
Is there any way I can adjust the number of variables that can fit in a line?
I'd appreciate it if you could help me
python print
Hello, everyone
I think you can adjust it using print('test', end=') and print().
a = 10
b = 7
c = 5
d = 9
e = 8
f = 2
l = [a, b, c, d, e, f] # I made it into a list
dec_print(row, col): # Gets the number of lines and lines to print
i = 0
For_in range(row): # Repeat enough!
For c in range (col): # Repeat as many times!
if i+c < len(l):
print(l[i + c], end=' ')
print()
i = i + col
rc_print(3,2)
# 10 7
# 5 9
# 8 2
rc_print(2,3)
# 10 7 5
# 9 8 2
rc_print(2,5)
# 10 7 5 9 8
# 2
Just in case, an easy way ver.
a=10
b=7
c=5
d=9
e=8
f=2
print(a, b, c)
print(c, e, f)
Have a nice day
def myprint(n, result):
for i in range(len(result)):
if i%n == 0:print()
print(result[i], end = ' ')
>>> rgs = tuple(range(30));myprint(5, rgs)
0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
15 16 17 18 19
20 21 22 23 24
25 26 27 28 29
>>> myprint(7, rgs)
0 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29
Alternatively, you can use the enumerate function
def myprint(n, result):
for k, v in enumerate(result, 1):
print('{}'.format(v), end='\n' if k % n == 0 else ' ')
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
581 PHP ssh2_scp_send fails to send files as intended
912 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
578 Understanding How to Configure Google API Key
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.