length = 0
for n in range(1,101):
print "Sequence #:", n
while n != 1:
print n,
if n % 2 == 0:
n = n / 2
length = length + 1
else:
n = (n * 3) + 1
length = length + 1
if n == 1:
print n
length = length + 1
print "The sequence above contains", length, "numbers"
length = 0
My Problem:
The python code above calculates the hailstone sequence for numbers 1 – 100 and displays the length of the sequence afterwards. How can I display the number with the longest sequence and its corresponding length after all calculations are done?
This will keep track of the max length and sequence and display them at the end. The lines marked with a
##are the additions to your original code.