Skip to content

Instantly share code, notes, and snippets.

@TomColBee
Created August 8, 2018 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomColBee/02b91b3789879b2b1cd7d8d601c6259b to your computer and use it in GitHub Desktop.
Save TomColBee/02b91b3789879b2b1cd7d8d601c6259b to your computer and use it in GitHub Desktop.
Diamond Shaped Star Letters
def diamond_letters(n):
# convert string to upper case
n = n.upper()
# create letter string
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# find given letter n in the letters string and return index+1
n = letters.find(n) + 1
orig_n = int(n)
orig_n_2 = int(n)
# first line of star
spaces = int(n-1)
print(" " * spaces + "A")
# middle section
for i in range(1,n):
spaces = int(n - 2)
middle_spaces = int((i*2)-1)
letter = letters[i]
print(" " * spaces + letter + " " * middle_spaces + letter)
n -= 1
# end section
for i in range(orig_n, 2,-1):
spaces = int(orig_n - (orig_n_2-1))
middle_spaces = int((i*2)-5)
letter = letters[i-2]
print(" " * spaces + letter + " " * middle_spaces + letter)
orig_n += 1
# last line of star
spaces = int(orig_n_2-1)
print(" " * spaces + "A")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment