Skip to content

Instantly share code, notes, and snippets.

@roman-on
Created April 28, 2020 20:14
Show Gist options
  • Save roman-on/01617ede24d18e6558f5d660d32d1598 to your computer and use it in GitHub Desktop.
Save roman-on/01617ede24d18e6558f5d660d32d1598 to your computer and use it in GitHub Desktop.
"""
The function accepts two parameters: the first is a single character, the second is a maximum size.
The function returns a string representing an "arrow" structure (see example), which is built from the input character,
with the center of the arrow (the longest line) being the length of the size passed as a parameter.
Example of the arrow function run:
In this example, you pass the asterisk character * and the maximum size 5. That is, the middle row is 5 in length.
print(arrow('*', 5))
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
"""
def arrow(my_char, max_length):
result = ""
i = 0
while i <= max_length-1:
i += 1
new = my_char * i
result += new
result += "\n"
while i >= 0:
i -= 1
new = my_char * i
result += new
result += "\n"
add_space = result.replace("", " ")
return add_space
def main():
<your code here>
if __name__ == "__main__":
main()
print(arrow('*', 5))
add_space = arrow('*', 5)
print (add_space)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment