Python Program to Print Exponentially Increasing Star Pattern

Write a Python Program to Print Exponentially Increasing Star Pattern using For Loop and While Loop with an example.

Python Program to Print Exponentially Increasing Star Pattern using While Loop

This Python program allows user to enter the total number of rows. Next, we used Python Nested While Loop to print exponentially increasing of stars from 1 to user-specified maximum value (rows).

# Python Program to Print Exponentially Increasing Star Pattern
import math

rows = int(input("Please Enter the total Number of Rows  : "))

print("Exponentially Increasing Stars") 
i = 0
while(i <= rows):
    j = 1
    while(j <= math.pow(2, i)):        
        print('*', end = '  ')
        j = j + 1
    i = i + 1
    print()
Python Program to Print Exponentially Increasing Star Pattern

Python Program to Print Exponentially Increasing Stars using For Loop

This exponentially increasing pattern of stars program is the same as the first example. However, we replaced the While Loop with For Loop.

# Python Program to Print Exponentially Increasing Star Pattern
import math

rows = int(input("Please Enter the total Number of Rows  : "))

print("Exponentially Increasing Stars") 
for i in range(rows + 1):
    for j in range(1, int(math.pow(2, i) + 1)):        
        print('*', end = '  ')
    print()
Please Enter the total Number of Rows  : 3
Exponentially Increasing Stars
*  
*  *  
*  *  *  *  
*  *  *  *  *  *  *  *  
>>> 

Python Program to Print Exponentially Increasing Stars Example 2

This Python program allows the user to enter his/her character. Next, Python prints an exponentially increasing pattern of user-specified character.

# Python Program to Print Exponentially Increasing Star Pattern
import math

rows = int(input("Please Enter the total Number of Rows  : "))
ch = input("Please Enter any Character  : ")

print("Exponentially Increasing Stars") 
for i in range(rows + 1):
    for j in range(1, int(math.pow(2, i) + 1)):        
        print('%c' %ch, end = '  ')
    print()
Please Enter the total Number of Rows  : 4
Please Enter any Character  : #
Exponentially Increasing Stars
#  
#  #  
#  #  #  #  
#  #  #  #  #  #  #  #  
#  #  #  #  #  #  #  #  #  #  #  #  #  #  #  #  
>>>