inputStr = input(“Input a number: “)
number = int(inputStr)
if number < 0:
print (“You entered a negative number.”)
else:
print (“Sequence for”, number, “=>”,
number)
while number > 1:
if number%2 == 0:
number=int(number/2)
else:
number=number*3+1
print (number)
This program prompts the user for an integer and displays the hailstone sequence, which is:
For any positive integer:
1. If the number is even, divide it in half
2. If the number is odd, multiply it by 3 then add 1
3. If the number reaches 1, stop; otherwise go to step 1