Created
April 3, 2021 13:12
-
-
Save kissgyorgy/6984e5cf56f70e6492b395acc8d6a90b to your computer and use it in GitHub Desktop.
Python: Print a diamond shape with as many lines as the input number.
This file contains hidden or 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
# For example, if the input is 5, the shape should look like this: | |
# * | |
# *** | |
# ***** | |
# *** | |
# * | |
import math | |
lines = int(input('How many lines? ')) | |
half = math.floor(lines / 2) | |
for current_line in range(lines): | |
distance_from_half = abs(half - current_line) | |
padding = distance_from_half | |
stars = lines - padding * 2 | |
print(' ' * padding + '*' * stars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment