In this article, we will show you, How to write a Python Program to Print Exponentially Increasing Star Pattern using For Loop and While Loop with 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 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()
OUTPUT
Python Program to Print Exponentially Increasing Star Pattern using For Loop
This exponentially increasing pattern of stars program is same as 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()
OUTPUT
Python Program to Print Exponentially Increasing Stars Example 2
This program allows user to enter his/her own character. Next, it will print 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()
OUTPUT