Skip to content

Categories:

Lab3

In this lab, i am prompting the user for an integer and display, for that integer, the hailstone sequence. Continue prompting the user for a number to process until a negative number is entered, indicating the user wishes to quit the program. basically, if the number is even then it will be divided b half. if the number is odd then python will multiply that number by 3 and add 1. when the number reaches 1 then the program will end.

Source Code:

inputStr=raw_input(“Input a number: “)
number=int(inputStr)
while number>1:
if number%2>0:
number=number*3+1
else:
number=number/2
print number