0

if I have a simple for loop like:

for i in range(10):
   total = 0
   total = total + i
   print(total)

How can I print the loops once/together like:

1 2 3 4 5 6 7 8 9 

Instead of every loop by itself:

1
2
3 etc
AL12
  • 51
  • 6

1 Answers1

2
for i in range(10):
   total = 0
   total = total + i
   print(total,end=" ")

The ability of print function, end of the each line changing from \n to " "