PYTHON PROGRAMMING LAB Exp 10

Опубликовано: 19 Январь 2024
на канале: DIWAKAR TIWARY
126
2

Exp No 10 Write a Python program to construct the following pattern, using a nested for loop
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
SOURCE CODE:
Set the value of 'n' to 5 (this will determine the number of lines in the pattern)
n = 5
Iterate through the range of numbers from 0 to 'n' (exclusive)
for i in range(n):
Iterate through the range of numbers from 0 to 'i' (exclusive) for each 'i' in the outer loop
for j in range(i):
Print '*' followed by a space without a new line (end="" ensures printing in the same line)
print('* ', end="")
Move to the next line after printing '*' characters for the current 'i'
print('')

Iterate through the range of numbers from 'n' down to 1 (inclusive), decreasing by 1 in each iteration
for i in range(n, 0, -1):
Iterate through the range of numbers from 0 to 'i' (exclusive) for each 'i' in the outer loop
for j in range(i):
Print '*' followed by a space without a new line (end="" ensures printing in the same line)
print('* ', end="")
Move to the next line after printing '*' characters for the current 'i'
print('')

INPUT AND OUTPUT:

*
* *
* * *
* * * *
* * *
* *
*
*


На этой странице сайта вы можете посмотреть видео онлайн PYTHON PROGRAMMING LAB Exp 10 длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь DIWAKAR TIWARY 19 Январь 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 126 раз и оно понравилось 2 зрителям. Приятного просмотра!