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 :: append row to array python 
Python :: rename files in folder python 
Python :: how to move columns in a dataframen in python 
Python :: how to add a list to dataframe in python 
Python :: add download directory selenium python 
Python :: python how to get alphabet 
Python :: how to make index column as a normal column 
Python :: how to use colorama 
Python :: numpy multidimensional indexing 
Python :: xaxis matplotlib 
Python :: python csv add row 
Python :: flask migrate install 
Python :: python loop through array backwards 
Python :: python math cube root 
Python :: How to find the three largest values of an array efficiently, in Python? 
Python :: convert string representation of a list to list 
Python :: python download file from web 
Python :: Import "flask" could not be resolved 
Python :: python get object attribute by string 
Python :: text size legend to bottom matplotlib 
Python :: python pandas replace nan with null 
Python :: on member leave event in discord.py 
Python :: convert categorical data type to int in pandas 
Python :: how to save array python 
Python :: numpy correlation 
Python :: pil image base64 
Python :: python snake game 
Python :: logging the terminal output to a file 
Python :: ready command discord.py 
Python :: Python pandas drop any row 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =