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
In order to get the output to look like it does, you need to use a counter initialize it to 0. Then after you print the number with print(number, end='\t') you must increment the counter. If the counter reaches a multiple of 10 (that is, if count % 10 == 0) then you must terminate the print line, with print().
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:
25the output is:
25 76 38 19 58 29 88 44 22 11Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images
Write multiple if statements: If car_year is before 1967, print "Probably has few safety features." (without quotes). If after 1971, print "Probably has seat belts.". If after 1991, print "Probably has electronic stability control.". If after 2002, print "Probably has tire-pressure monitor.". End each phrase with period and newline. Remember that print() automatically adds a newline. Ex: car_year = 1995 prints: