Write a python code to get the given pattern without using ‘FOR’ loop. A minimum of six WHILE LOOPS must be used effectively to get the output.
Question
Write a python code to get the given pattern without using ‘FOR’ loop.
A minimum of six WHILE LOOPS must be used effectively to get the output.
Solution
Sure! Here's a Python code that uses six while loops to generate the given pattern:
# Initialize the variables
i = 1
j = 1
k = 1
l = 1
m = 1
n = 1
# First while loop
while i <= 5:
print('*' * i)
i += 1
# Second while loop
while j <= 4:
print('*' * (5 - j))
j += 1
# Third while loop
while k <= 5:
print(' ' * (k - 1) + '*' * (6 - k))
k += 1
# Fourth while loop
while l <= 4:
print(' ' * (5 - l) + '*' * l)
l += 1
# Fifth while loop
while m <= 5:
print(' ' * (m - 1) + '*' * (6 - m))
m += 1
# Sixth while loop
while n <= 4:
print(' ' * (4 - n) + '*' * (n + 1))
n += 1
This code will generate the given pattern using six while loops. Each while loop is responsible for printing a specific part of the pattern.
Similar Questions
____________ will be the output of the following python programN = 6while N <= 6: if N < 6: N = N + 1 print(N)
What will be the value of "i" in the following "for loop" statement?for i in range(1, 6): print(i)
How many times will the following "for loop" iterate?for i in range(5): print(i)
Which of the following loops is not supported in Python?forwhiledo-whileNone of the above
Looping-4Read a integer N and print a character pattern with N rows.For example if N=5, the pattern isABBCCCDDDDE E E E E
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.