In: Computer Science
Write a Python program, in a file called StickFigure.py, which, given a value for the total height of a stick figure, uses a recursive function to generate the stick figure pattern as shown below. The recursive function is used to print the entire figure. Note that the head, arms and legs stay the same, but the body can be different lengths, depending on what the user enters as the height of the figure. The "body" length is always 3 lines shorter than the value entered for the height (because of the 3 lines needed for the head, arms and legs). Sample input/output for two different test runs:
Enter the height (in lines) of the stick figure: 7 O \ / | | | | / \ Enter the height (in lines) of the stick figure: 4 O \ / | / \
Note: You may assume that the input value is always greater than 3.
If you have any doubts, please give me comment...
Code:
def draw(n):
if n==3:
print("/ \\")
else:
print(" |")
draw(n-1)
def main():
n = int(input("Enter the height (in lines) of the stick figure: "))
print(" O")
print("\\ /")
draw(n)
main()