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.’)
please enter a number:50
you entered a positive number. Countdown
sequence for 50 =>
50
25
12
6
3
1
please enter a number:10
you entered a positive number. Countdown
sequence for 10 =>
10
5
2
1
please enter a number:100
you entered a positive number. Countdown
sequence for 100 =>
100
50
25
12
6
3
1
please enter a number:
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,’sequence’)
Sequence for 100 =>
100
50
25
76
38
19
58
29
88
44
22
11
34
17
52
26
13
40
20
10
5
16
8
4
2
1
26
The number that has the longest hailstone is number 97 with 119 sequences.
>>>
In this lab we test the theory of hailstone with python. We assigned the equation according with the number. If it was even the program if the number is even, divide it by two. If the number is odd, triple it and add one. Also we arrange our program to discover which number had the longest hailstone and it point out 97 as the longest hailstone.