Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Number pyramid pattern in python

# pyramid number pattern
n = 5
for i in range(n):
    for j in range(n - i - 1):
        print(' ', end='')
    for k in range(2 * i + 1):
        print(k + 1, end='')
    print()
Comment

prints a pyramid in python

row_len = int(input("Enter the length of the pyramid: "))
col_len = row_len*2 - 1                # calculate the maximum number of columns, depending on the row_len
for row in range(row_len):
    nb_whitespaces = col_len//2 - row  # calculate number of whitespaces that should be prints at first of each row
    nb_asterisk = row+1                # calculate how many Asterisk that should be prints for each row
    print(nb_whitespaces * " " + "* " * nb_asterisk)

# By Omar Alanazi
Comment

python pyramid

for row in range(row_len := int(input("Enter the length of the pyramid: "))):
    print(((row_len * 2 - 1) // 2 - row) * " " + "* " * (row + 1))
# By Omar Alanazi
# Output example (if user enters 3)
#  * 
# * * 
#* * * 
Comment

python pyramid pattern

rows = int(input("Enter number of rows: "))

for i in range(rows):
    for j in range(i+1):
        print("* ", end="")
    print("
")
Comment

pyramid pattern in python

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

PREVIOUS NEXT
Code Example
Python :: matplotlib location legend 
Python :: how to start an exe file in python 
Python :: list files python 
Python :: get input from user in python 
Python :: how to make table using python 
Python :: get only every 2 rows pandas 
Python :: decision tree algorithm python 
Python :: handle errors in flask 
Python :: yahoo finance api python 
Python :: streamlit change tab name 
Python :: remove env variable python 
Python :: python Decompress gzip File 
Python :: pd.read_excel column data type 
Python :: youtube-dl python get file name 
Python :: django get settings 
Python :: how to use elif in python 
Python :: how to convert utf-16 file to utf-8 in python 
Python :: find size of mongodb collection python 
Python :: show equation using geom_smooth 
Python :: how to add an item to a dictionary in python 
Python :: How to colour a specific cell in pandas dataframe 
Python :: datetime library 
Python :: mss python install 
Python :: get variable name python 
Python :: flask tutorials 
Python :: reportlab python draw line 
Python :: python sum array 
Python :: python count code, Count number of occurrences of a given substring 
Python :: python - change the bin size of an histogram+ 
Python :: python remove items from list containing string 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =