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 secondary y axis 
Python :: keras tuner 
Python :: Changing the number of ticks on a Matplotlib plot axis 
Python :: datetime.datetime.fromtimestamp() 
Python :: python with file 
Python :: redirect stdout to variable python 
Python :: python render_template 
Python :: pandas shift all columns 
Python :: python list to string without brackets 
Python :: python for else 
Python :: what is kali 
Python :: make blinking text python1 
Python :: python selenium get text of div 
Python :: Conversion of number string to float in django 
Python :: how to play audio in python 
Python :: handle queries in listview django 
Python :: how to use inverse trigonometric functions in python 
Python :: pandas filter length of string 
Python :: filter function in pandas stack overflow 
Python :: python var_dump 
Python :: multipart/form data multipart encoder python 
Python :: when was python created 
Python :: python append a file and read 
Python :: python binary tree 
Python :: how to add mouse button in pygame 
Python :: Handling Python DateTime timezone 
Python :: build dataframe from dictionary 
Python :: tkinter text blurry 
Python :: datetime to int in pandas 
Python :: python delete text in text file 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =