Skip to content

Commit 9988838

Browse files
authoredJan 4, 2023
Create unit7_ex7.2.7.py
1 parent e28210a commit 9988838

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
 

‎unit7_ex7.2.7.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# exersice 7.2.7 from unit 7
2+
'''
3+
Write a function called arrow defined as follows:
4+
5+
def arrow(my_char, max_length):
6+
The function accepts two parameters: the first is a single character, the second is a maximum size.
7+
The function returns a string representing an "arrow" structure (see example), built from the input, where the center of the arrow (the longest line) is the length of the size passed as a parameter.
8+
9+
An example of running the arrow function
10+
print(arrow('*', 5))
11+
*
12+
* *
13+
* * *
14+
* * * *
15+
* * * * *
16+
* * * *
17+
* * *
18+
* *
19+
*
20+
'''
21+
22+
def arrow(my_char, max_length):
23+
arrow_str = ''
24+
for i in range(max_length):
25+
arrow_str += (my_char + ' ') * i + my_char + '\n'
26+
for i in range(max_length - 2, -1, -1):
27+
arrow_str += (my_char + ' ') * i + my_char + '\n'
28+
return arrow_str
29+
30+
def main():
31+
print(arrow('*', 5))
32+
33+
if __name__ == "__main__":
34+
main()

0 commit comments

Comments
 (0)
Please sign in to comment.