Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a Python program that prints Snowflake numbers.Snowflake numbers start wit

ID: 3769833 • Letter: W

Question

Write a Python program that prints Snowflake numbers.Snowflake numbers start with an integer (ask the user to enter one), if this number is even, divide it by two and the result is the new number. But, if the number is odd, multiply it by three and add one, and this will be the new number. The sequence ends when the value reaches 1. If not, repeat the above process.

So, for example, if the starting number is 11, your program should output the following sequence of snowflake numbers:11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1


Hint: in Python, you can figure if a number is even or odd by using the remainder operator (%) and if condition. Also, if you want to print a integer value of a double, you can cast it as int (ex: int(3.0) will be 3)

Explanation / Answer

N = input("Enter n")
print
print N,
while(N!=1) :
if N%2 == 1:
N = 3*N+1
else:
N = N/2
print N,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote