LAB3 Python2

This program is create to find the hailstone sequence of any positive number by using given algorithm. The loop is use to find the sequence until it reaches number 1.

Another loop  can be use to find the number that has the longest hailstone.

Source code:

Part 1:

num=1
while num>0:
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*3)+1
num=result
print (num)
else:
print(‘Invalid input, program is closed.’)

Part 2:

num=1
count=1
temp=0
highest=1

for num in range (1,101):
nex=num
result=0
if num>0:
print(‘Sequence for’, num, ‘=>’)
while result != 1:
if (num%2)==0:
print (num)
result=num//2
num=result
count=count+1
elif (num%2)!=0:
print (num)
result=(num*3)+1
num=result
count=count+1
print (num)
print (count)
if count>temp:
temp=count
highest=nex
count=1
print (‘The number that has the longest hailstone is number ‘, highest,
‘ with ‘, temp, ‘ sequences.’)