How to print a star pattern without using loop in the python programming language
How to print a star pattern without using loop in the python programming language. There are you will learn how to print the star pattern without using the loop.
Take an example to print this star pattern through a python program:
# How to print a star pattern without
# using loop in the python programming language
import math
# It's the recursive function
# to print the star pattern
def starPattern(n = 0, i = 1, r = 1):
print (end="*") if (int (math.sqrt(math.pow((i - (2 * n - 1) *(r - 1) - n), 2))) < r) else print (end=" ")
if ((i - (2 * n - 1) * (r - 1)) % (2 * n - 1) == 0):
print (end="\n")
r += 1
if (i < n * (2 * n - 1)):
i += 1
starPattern(n, i, r)
# It's the driver code for computing
print ("-----Enter the size of the pattern-----")
# size of the pattern
x = int (input ())
# This will print the pattern
starPattern(x)
Output:
-----Enter the size of the pattern-----
10
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
Tags:
# print star pattern without using loop in python
# write a program to print done without using any loop in python
# print all numbers between 1 to n without using any loop in python