lab3

Today i will be working on python lab 3. This lab is called hailstone algorithm, in this lab basically what i had do was write sequence of numbers and  If the number is even, divide it in half and If the number is odd, multiply it by 3 then add and also had make loop If the number reaches 1 stop, otherwise go to 1.

num=1

while num>0:

num_in=input(‘please enter a number:’)

num=int(num_in)

result=0

if num>0:

print (‘you entered a positive number. Countdown’)

print (‘sequence for’,num, ‘=>’)

while result !=1:

if (num%2)==0:

print (num)

result=num//2

num=result

elif (num%2)!=0:

print (num)

result=num//2

num=result

print (num)

else:

print(‘invalid input, program is closed.’)