Skip to content

Instantly share code, notes, and snippets.

@shinysu
Created September 19, 2021 04:07
Show Gist options
  • Save shinysu/288c58a5b48adc446da356e6a57b6b5f to your computer and use it in GitHub Desktop.
Save shinysu/288c58a5b48adc446da356e6a57b6b5f 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 star_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)
star_row(i)
blanks -= 1
print()
"""
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
| | |
| | |
| | |
| | |
+ - - - - + - - - - +
"""
def plus_line():
print("+ ", end='')
for i in range(4):
print('- ', end='')
print("+ ",end='')
for i in range(4):
print('- ', end='')
print("+")
def other_line():
print("| ", end='')
for i in range(4):
print(" ", end='')
print("| ", end='')
for i in range(4):
print(" ", end='')
print("|")
for x in range(1, 12):
if x == 1 or x == 6 or x == 11:
plus_line()
else:
other_line()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment