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') Ex: If the input is: 25 the output is: 25 76 38 19 58 29 88 44 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 My Code: n = int(input()) print(n, end='\t') i = 1 while n > 1: if not i % 10: print(n, end='\n') if n % 2 == 0: n = n//2 print(n, end='\t') else: n = 3*n+1 print(n, end='\t') i += 1 print() Output: Screenshot attached!
4.15 LAB: Hailstone sequence
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')
Ex: If the input is:
25
the output is:
25 76 38 19 58 29 88 44 22 11
34 17 52 26 13 40 20 10 5 16
8 4 2 1
My Code:
n = int(input())
print(n, end='\t')
i = 1
while n > 1:
if not i % 10:
print(n, end='\n')
if n % 2 == 0:
n = n//2
print(n, end='\t')
else:
n = 3*n+1
print(n, end='\t')
i += 1
print()
Output:
Screenshot attached!
![=
zyBooks My library > DAT 210: Data Programming Languages home > 4.15: LAB: Hailstone sequence
Latest submission - 3:04 PM CDT on 10/10/22
Only show failing tests
1: Compare output
Output differs. See highlights below.
Input
Your output
Expected output
2: Compare output
25
Your output
25
34
8
Expected output
25
34
8
Input 1
1→
76
17
4
1
76
17
4
Special character legend
38
52
N
38
52
2
19
26
1→
19
26
1
58
13
58
13
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
29
40
29
40
88
20
88
20
44
10
zyBooks catalog
Download this submission
44
10
Total score: 0/10
22
5
22
5
0/2
0/2
? Help/FAQ
Raza Aamir](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fc4df0c76-74ac-4935-953f-f50d8c4d6716%2F276958a0-b3b7-4273-9972-929a664fc823%2F7o54xw_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)