Skip to content

Instantly share code, notes, and snippets.

@shinysu
Last active September 20, 2021 17:02
Show Gist options
  • Select an option

  • Save shinysu/53ad0ecfae17851cd8d626d2ad2f58ae to your computer and use it in GitHub Desktop.

Select an option

Save shinysu/53ad0ecfae17851cd8d626d2ad2f58ae to your computer and use it in GitHub Desktop.
patterns
'''
*
* *
* * *
* * * *
* * * * *
* * * * * *
'''
def star_row(n):
for i in range(n):
print('*', end=' ')
rows = int(input("Enter the number of rows: "))
for i in range(1, rows+1):
star_row(i)
print()
'''
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
'''
def number_row(n):
for i in range(n):
print(i+1, end=' ')
rows = int(input("Enter the number of rows: "))
for i in range(1, rows+1):
number_row(i)
print()
'''
*
* *
* * *
* * * *
* * * * *
* * * * * *
'''
def spaces(n):
for i in range(n):
print(end=' ')
def star_row(n):
for i in range(n):
print('*', end=' ')
rows = int(input("Enter the number of rows:"))
blanks = rows
for i in range(rows+1):
spaces(blanks)
star_row(i)
blanks -= 1
print()
'''
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
'''
def spaces(n):
for i in range(n):
print(end=' ')
def number_row(n):
for i in range(n):
print(i+1, end=' ')
rows = int(input("Enter the number of rows:"))
blanks = rows
for i in range(rows+1):
spaces(blanks)
number_row(i)
blanks -= 1
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment