1rows = 6 #Pattern(1,121,12321,1234321,123454321)
2for i in range(1, rows + 1):
3 for j in range(1, i - 1):
4 print(j, end=" ")
5 for j in range(i - 1, 0, -1):
6 print(j, end=" ")
7 print()
1n = 3
2for i in range(1, n+1):
3 print(f"{' '*(n-i)}{' *'*i}"[1:])
4
5# Output:
6# *
7# * *
8#* * *
1def pattern(n):
2 for i in range(0,n):
3 for j in range(0, i+1):
4 print("* " , end="")
5 print("\r") pattern(5
1# install pyramid (basic, if path is not set yet)
2py -m pip install pyramid
3# or set PATH to use pip:
4setx PATH "%PATH%;C:\<path\to\python\directory\>\Scripts"
5pip install pyramid
6# or
7pip3 install pyramid --upgrade
8# if "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed" [!]:
9py -m pip install --trusted-host pypi.python.org pip pyramid
10# if PermissionError: [WinError 5] Access is denied
11py -m pip install --user pyramid
12# or via creating a virtual environment venv:
13py -m venv c:\path\to\new\environment
14# then execute:
15c:\path\to\new\environment\Scripts\activate.bat
1#Use this to shortern a task that you may want to repeat
2#Used for making custom commands
3def paste(a, b)
4 for i in b:
5 print(a)
6
7
8while True:
9 paste("Python is Cool!!!", 3)
10
11#Output:
12#Python is Cool!!!
13#Python is Cool!!!
14#Python is Cool!!!
15
16
17
18
19
20## - ANOTHER EXAMPLE - ##
21
22
23
24
25
26happy = "NEUTRAL"
27
28def yes():
29 happy="TRUE"
30 print("Thank you!")
31
32def no():
33 happy="FALSE"
34 print("That's not nice!")
35
36answer=str(input("Do you like my new shoes? (y/n) ")
37if answer=="yes" or "y" or "Yes" or "Y" or "YES":
38 yes()
39elif answer=="no" or "n" or "No" or "N" or "NO":
40 no()