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 :: How to correctly call url_for and specify path parameters 
Python :: app.callback output is not defined 
Python :: Not getting values from Select Fields with jQuery 
Python :: if space bar pressed pygame 
Python :: Django, limit queryset without slicing 
Python :: python while loop command gaming code 
Python :: _tkinter.TclError: invalid command name ".!canvas" 
Python :: EDA dataframe get missing and zero values 
Python :: python complement operator 
Python :: clear notebook output 
Python :: ring Copy Lists 
Python :: print all gpu available tensor 
Python :: Select right color to threshold and image with opencv 
Python :: check string on substring godot 
Python :: equivalent of geom smooth function in python using plotline lib 
Python :: logout from linux using python 
Python :: any value in list will retrun true python 
Python :: Find the 15th term of the series?0,0,7,6,14,12,21,18, 28 
Python :: Matplotlib-Object oriented interface 
Python :: python apply file line 
Python :: pls help i need tkintwr help plspslspslspsl help tkinter 
Python :: jupter notebook save session variables 
Python :: keras name layers 
Python :: pyglet key hold 
Python :: python remainder divide by 60 
Python :: python function guts 
Python :: how to make a function input optional in python 
Python :: python ravel function output 
Python :: python inline assignment 
Python :: rename multiple value in column in pandas 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =