Created
January 31, 2019 15:42
-
-
Save davegotz/155d567bc77f63196d406ff6aeb53903 to your computer and use it in GitHub Desktop.
Symbol pattern with functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prints the requested number of symbols without a newline. | |
def print_symbol(symbol, count): | |
for i in range(count): | |
print(symbol, end='') | |
# Draws a single line of spaces and symbols using the given size/line number. | |
def print_line(size, symbol, line_num): | |
# Print spaces | |
print_symbol(' ', line_num) | |
# Print symbols | |
print_symbol(symbol, size-line_num) | |
# Print newline. | |
print() | |
# Draw a pattern of size 'size' using 'symbol' as the | |
# character that makes up the pattern. | |
def print_pattern(size, symbol): | |
for line_num in range(size): | |
print_line(size, symbol, line_num) | |
# Draw patterns of different kinds. | |
def main(): | |
# Draw a star pattern | |
print_pattern(6, '*') | |
# Draw a money pattern | |
print_pattern(3, '$') | |
# Draw a pizza pattern | |
print_pattern(1238, 'PIZZA') | |
# Run the program | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment