Doubling Sequence Generator

Write a Python program that asks for two integers m and n. The program should print a sequence of numbers, each one being the double of its predecessor, starting from m and as long as the number is less than n.

Example 1:

Input: m = 2, n = 20 
Output: 2, 4, 8, 16

Example 2:

Input: m = 1, n = 50 
Output: 1, 2, 4, 8, 16, 32

Use a while loop to keep doubling m as long as it is less than n.

m = int(input("Enter the first number: "))
n = int(input("Enter the maximum limit: "))
while m < n:
    print(m)
    m *= 2

© Let’s Data Science

LOGIN

Unlock AI & Data Science treasures. Log in!