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 :: feature scaling in python 
Python :: pyspark overwrite schema 
Python :: assign python 
Python :: numpy get variance of array 
Python :: how to use a string variable as a variable name in python 
Python :: integer colomn to datetime pandas 
Python :: remove specific word from string using python 
Python :: int to string python 
Python :: python how to split a number 
Python :: Python Removing Directory or File 
Python :: python writelines 
Python :: merge two dictionaries in a single expression 
Python :: matplotlib cheatsheet 
Python :: The Python path in your debug configuration is invalid. 
Python :: python function as parameter 
Python :: python wait for x seconds 
Python :: boxplot groupby pandas 
Python :: datetime to int in pandas 
Python :: pandas backfill 
Python :: how can i make a list of leftovers that are str to make them int in python 
Python :: fillna with mode pandas 
Python :: opencv python image capture 
Python :: or operator django 
Python :: multiple variables in for loop python 
Python :: how to export DataFrame to CSV file 
Python :: pandas select 2nd row 
Python :: seaborn pairplot 
Python :: how to add header in csv file in python 
Python :: print() 
Python :: how to convert to string in python 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =