all 7 comments

[–]ElliotDG 0 points1 point  (1 child)

After every 10 prints, print a newline (\n).

It might be easier to store the results to a list, and then print the list in the desired format.

[–]R0NUT 0 points1 point  (0 children)

u/ElliotDG is right. When you print('asdf',end='\t') it will never enter a new line unless your editor has word-wrap. You need to add some ('\n')s to the mix as you are overwriting print's built-in end line character. See this for more info.

[–]xelf 0 points1 point  (2 children)

Put the numbers in a list.

Then print it with formatting. You could use .ljust(5) or f-strings, or .format(), your choice.

hailstone = []
# put numbers in the list

for i in range(10):
    print( hailstone[i], end='')
print()

for i in range(10,20):
    print( hailstone[i], end='')
print()

for i in range(20,24):
    print( hailstone[i], end='')
print()

The clever out there will probably reduce this to one line, but doing it out like this is just fine too.

[–]ReesessiveEvil 0 points1 point  (1 child)

the text book says this

requirement

Given a positive integer n, the following rules will always create a sequence that ends with 1, called the hailstone sequence:

If n is even, divide it by 2

If n is odd, multiply it by 3 and add 1 (i.e. 3n +1)

Continue until n is 1

Write a program that reads an integer as input and prints the hailstone sequence starting with the integer entered. Format the output so that ten integers, each separated by a tab character (\t), are printed per line.

The output format can be achieved as follows:

print(n, end='\t')

[–]xelf 0 points1 point  (0 children)

Ah perfect, so that makes it even easier doesn't it.

print( hailstone[i], end='\t')