Skip to content

Instantly share code, notes, and snippets.

@c0dyhi11
Created February 4, 2022 21:52
Show Gist options
  • Save c0dyhi11/4c0ce6f8dc1595e105faff06d8de9a32 to your computer and use it in GitHub Desktop.
Save c0dyhi11/4c0ce6f8dc1595e105faff06d8de9a32 to your computer and use it in GitHub Desktop.
Draw a diamond on the screen the size that the user wants
def is_number_input(user_input):
if not user_input.isnumeric():
print("You must input a whole number!")
return 0
user_input = int(user_input)
if user_input > 35:
print("Your number must be smaller than 35!")
return 0
elif user_input < 2:
print("Your number must be larger than 1!")
return 0
return user_input
def is_yes_no_input(input):
if input.lower() == "yes" or input.lower() == "y":
print("Yay!")
return True
else:
print("I'll take that as a no!, Goodbye!")
return False
def draw_diamond_top(num):
for x in range(1, num + 1):
spaces = num - x
for y in range(0, spaces):
print(" ", end="")
for z in range(0, x):
print("* ", end="")
print()
def draw_diamond_bottom(num):
for x in reversed(range(1, num)):
spaces = num - x
for y in range(0, spaces):
print(" ", end="")
for z in range(0, x):
print("* ", end="")
print("")
def main():
again = True
while again is True:
user_input = input("What width diamond would you like? ")
valid_input = is_number_input(user_input)
if valid_input == 0:
continue
draw_diamond_top(valid_input)
draw_diamond_bottom(valid_input)
go_again = input("Would you like to draw another diamond? ")
again = is_yes_no_input(go_again)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment