Hello everyone! Welcome back to programminginpython.com, here in this post I am going to show you how to print a pattern of Letter C.
This is a continuation of the letter pattern printing series, in the previous tutorials I have explained the patterns of Letter A and Letter B.
Master the basics of data analysis in Python. Expand your skillset by learning scientific computing with numpy.
Take the course on Introduction to Python on DataCamp here https://bit.ly/datacamp-intro-to-python
You can also watch the video on YouTube here.
Task:
Python program to print the pattern of letter โCโ
Approach:
- Read an input integer for asking the sizeof 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 which is greater or equal to 8
- if yes, call the function
- 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, outer loop() for rows and inner loop for columns.
12345# Outer for loopfor i in range(n):# Inner for loopfor j in range(n + 1):-
- the first line of alphabet
1i == 0 - last line
1i == n - 1 - first column
1j == 0 and (i != 0 and i != n - 1)
- the first line of alphabet
-
- print
in remaining all cases.
- here we only do two things, print star(
Program:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
__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:


Print pattern C โ Code Visualization
Course Suggestion
Machine Learning everywhere! So I strongly suggest you to take the course below.
Course: Machine Learning Adv: Support Vector Machines (SVM) Python