pyramid pattern in python code example

Example 1: pyramid pattern in python

n = 3
for i in range(1, n+1):
  print(f"{' '*(n-i)}{' *'*i}"[1:])
  
# Output:
#  *
# * *
#* * *

Example 2: python pyramid

# install pyramid (basic, if path is not set yet)
py -m pip install pyramid
# or set PATH to use pip:
setx PATH "%PATH%;C:\<path\to\python\directory\>\Scripts"
pip install pyramid
# or
pip3 install pyramid --upgrade
# if "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed" [!]:
py -m pip install --trusted-host pypi.python.org pip pyramid
# if PermissionError: [WinError 5] Access is denied
py -m pip install --user pyramid
# or via creating a virtual environment venv:
py -m venv c:\path\to\new\environment
# then execute:
c:\path\to\new\environment\Scripts\activate.bat

Example 3: pattern in python

rows = 6                        #Pattern(1,121,12321,1234321,123454321)
for i in range(1, rows + 1):
    for j in range(1, i - 1):
        print(j, end=" ")
    for j in range(i - 1, 0, -1):
        print(j, end=" ")
    print()

Example 4: * pattern by python

def pattern(n):    
  for i in range(0,n):       
    for j in range(0, i+1): 
      print("* " , end="")         
      print("\r") pattern(5