Python Programmer Logo Python Programmer Python Programmer Logo


How to print out a pattern in Python (using keyboard symbols)!

Below is the python file I used in this video and the actual video


The video file

File Download Date Modified
Cool Tkinter Widgets Download File 11 Feb 2024

The actual code in the file



#Welcome back to another python programming tutorial
"""Today we're gonna be building a program that lets
you print out a pattern using a for loop"""

#Start with some general numbers realted with the pattern

i = 5
j = 2
h = 3

#Now apply the for loop
for num in range(i):
    #Now print an asterisk for each i
    print("*"*i,end="")
    """end="" lets you continue the string with another
    print statement"""
    #Now do a for loop corresponding to j
    for _ in range(j):
        #Now print a slash(/) for every j
        print("/"*j,end="")
        #Finally do another for loop for h
        for number in range(h):
            #Now print an exclamation mark for every h
            print("!"*h,end="\n")
            """\n will create a new line"""