-4

Using a range loop num set in python 3.7 and putting them all on the same line using the end='' After that though I need on a separate line a print statement but the end='' stops it from appearing on a separate line when I run the module. Any way to work around that? Or even put the range loop on the same line without using the end='' expression?

Expected Output

3,6,9,12,15,18,21,24,27,30
That's all folks!

My code:

#uses loop from 3-30 counting by 3's

for num in range(3, 33, 3):

    print (num, end=' ')

#print statement

print("That's all folks!")
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20
yawn18
  • 1
  • 2

3 Answers3

2

First, make a list of numbers. Say it's called number_list.

Then use ",".join(number_list) to join those numbers into a comma-delimited string.

Finally, print that string without end="", and then print your second thing.

alex
  • 6,818
  • 9
  • 52
  • 103
0

After some looking around found out an easy way was just

print("\nprintstatement")

which thus created a new line.

yawn18
  • 1
  • 2
0

Solution:

for num in range(3, 33, 3):
    print(num, end=' ')

print("\nThat's all folks!")

Better:

print(*[*range(3, 33, 3)], "\nThat's all folks!")
3 6 9 12 15 18 21 24 27 30 
That's all folks!
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20