hailstone.py, version 2

# -*- coding: utf-8 -*- """ Created on Mon Mar 8 11:15:16 2021 @author: rmontant """ while True: x0 = int( input('Honk! starting value? ') ) if x0 != 0: hailstone = [x0] while hailstone[-1] != 1: x0 = hailstone[-1] #if (x0 % 2) == 0: # xn = x0 // 2 # force integer division #else: # xn = 3 * x0 + 1 xn = (x0 // 2) if ((x0 % 2) == 0) else (3 * x0 + 1) hailstone.append(xn) print(hailstone) print('Sequence has', len(hailstone), 'elements') else: print('Goodbye!') break