def generate_hale_seq(num):
lnum = [num]
while num != 1:
if (num%2) == 0:
num = num//2
lnum.append(num)
else:
num = (num * 3) + 1
lnum.append(num)
return lnum
print(generate_hale_seq(10))
Write a program for Hailstone Sequence in Python
Carvia Tech  May 04, 2019  1 min read  46 views  Python Coding Problems
Hailstone Sequence
A hailstone sequence is a calculation of numbers that increase and decrease but eventually settles into a repeating pattern of the numbers 4, 2, 1. The sequence is generated by starting with any positive whole number greater than zero and completing the following steps:

If the number is even, divide it by 2 to calculate a new number

If the number is odd, multiple it by 3 and add 1 to calculate a new number

Repeat the above process for calculated numbers until the sequence 4, 2, 1 is generated.
[10, 5, 16, 8, 4, 2, 1]
Top articles in this category:
 Python coding challenges for interviews
 Python Flask Interview Questions
 Top 100 interview questions on Data Science & Machine Learning
 Google Data Scientist interview questions with answers
 Sequence of Differences in Python
 Write a program to check if the given word is Isogram & Pair isogram in python
 Write a program to find if a number is Lychrel Number in Python
Find more on this topic:
Machine Learning
Data science, machine learning, python, R, big data, spark, the Jupyter notebook, and much more
Last updated 1 week ago
Recommended books for interview preparation:
Similar Posts
 Installing PySpark with Jupyter notebook on Ubuntu 18.04 LTS
 Send email with attachment in Python
 Send rich text multimedia email in Python
 Blueprints in Flask API Development
 Singleton Design Pattern in Python
 SVM after LSTM deep learning model for text classification
 RuntimeError: get_session is not available when using TensorFlow 2.0
 Deploying Keras Model in Production with TensorFlow 2.0
 Python coding challenges for interviews
 Python Flask Interview Questions
Enter your email address to subscribe to this blog and receive notifications of new posts by email.