Skip to content

Instantly share code, notes, and snippets.

@kissgyorgy
Created April 3, 2021 13:12
Show Gist options
  • Save kissgyorgy/6984e5cf56f70e6492b395acc8d6a90b to your computer and use it in GitHub Desktop.
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.
# 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