Created
June 15, 2021 21:28
-
-
Save CraigTheKiwi/1707ae15edba48ddb542e890e487f8ad to your computer and use it in GitHub Desktop.
Solution for Cassidoo Newsletter (June 14) in Python
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
#!/bin/python3 | |
import sys | |
def arrow(direction, number): | |
start = -1 | |
# start going left | |
finish = number+1 | |
modifier = 1 #controls direction | |
counter = 0 | |
#switch to going right | |
if direction == "right": | |
finish = number | |
modifier = -1 #controls direction | |
counter = number - 1 | |
#deal with even numbers | |
double_point = True if number % 2 == 0 else False | |
while start < counter < finish: | |
print(counter*" ", "*",) | |
if direction == "right": | |
if counter == 0 : | |
modifier = 1 if not double_point else 0 # covers even numbers | |
double_point = not double_point | |
counter = counter + (1*modifier) | |
else: | |
if counter == number-1: | |
modifier = -1 if not double_point else 0 # covers even numbers | |
double_point = not double_point | |
counter = counter + (1*modifier) | |
args = sys.argv | |
try: | |
arrow(str(args[1]), int(args[2])) | |
except: | |
print("Please use the syntax: python3 cassidoo-jun-14.py <direction> <number>") | |
print(" i.e. python3 cassidoo-jun-14.py left 5") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment