Limited time sale - 50% OFF Learn in-demand data and AI skills on the 17th of July
Approach:
Read an input integer for asking the size of the letter using input()
Check if the entered number is greater than 8,
if yes, call the function `print_pattern()`
else, show a message to enter a number that is greater or equal to 8
print_pattern()
here we only do two things, print star(*) and print space(` `), just writing conditions so the pattern of *‘s and ` `’s will display the pattern ‘C’
following are 3 conditions for printing *’s
We have 2 loops, an outer loop() for rows and an inner loop for columns
# Outer for loop
for i in range(n):
# Inner for loop
for j in range(n + 1):
the first line of alphabet i == 0
last line i == n - 1
first column j == 0 and (i != 0 and i != n - 1)
print ` ` in remaining all cases.
Program:
__author__ = 'Avinash'
# Python3 program to print alphabet pattern C
# Function to display alphabet pattern
def print_pattern(n):
# Outer for loop for number of lines(rows)
for i in range(n):
# Inner for loop for logic execution
for j in range(n + 3):
# Print 1st line
if ((i == 0 or
# Print last line
i == n - 1) and
# For more reasonable curve
j > 0 or
# First column
(j == 0 and (i != 0 and i != n - 1))):
print("*", end="")
else:
print(" ", end="")
print()
# Size of the letter
num = int(input("Enter the size: \t "))
if num > 7:
print_pattern(num)
else:
print("Enter a size minimum of 8")
Output:
Python Program to print pattern of Letter CPython Program to print pattern of Letter C