In: Computer Science
def annoying_valley(n):
if n == 0:
print()
elif n == 1:
print("*")
elif n == 2:
print("./")
print("*")
print(".\\")
elif n == 3:
print("../")
print("./")
print("*")
print(".\\")
print("..\\")
elif n == 4:
print(".../")
annoying_valley(3)
print("...\\")
elif n == 5:
print("..../")
annoying_valley(4)
print("....\\")
elif n == 6:
print("...../")
annoying_valley(5)
print(".....\\")
else:
print("." * (n - 1) + "/")
annoying_valley(n - 1)
print("." * (n - 1) + "\\")
def annoying_int_sequence(n):
if n == 0:
return []
elif n == 1:
return [1]
else:
a = annoying_int_sequence(n-1)
b = a + [n]
return b * (n-1) + a
Please write two descriptions like below for these two function
def some_function(some_param):
"""
A summary/description of what the function does.
Parameters: give a brief description for each parameter (if there are any)
Returns: give a brief description of each of the return values (if there are any)
Pre-condition: detail any assumptions made by the function, i.e., any pre-condition that must be met in order for the function to work correctly
Post-condition: detail what we can expect to be true after the function has finished execution, i.e., its post-condition
""
The annoying_valley(n) function prints a sloping pattern while the function annoying_int_sequence(n) prints a recursive pattern.
The DocString is included with the code.
The necessary comments that will help you understand the solution.
def annoying_valley(n):
"""This Function prints a slope pattern
It takes a input number (n) which is used for the no of slope lines
It returns None
The input number must be >= 0 to see the output
The function first prints a decreasing /(forward slash) pattern and after that *(as a seperator) and it prints mirror image of the pattern above *
"""
if n == 0:
print()
elif n == 1:
print("*")
elif n == 2:
print("./")
print("*")
print(".\\")
elif n == 3:
print("../")
print("./")
print("*")
print(".\\")
print("..\\")
elif n == 4:
print(".../")
annoying_valley(3)
print("...\\")
elif n == 5:
print("..../")
annoying_valley(4)
print("....\\")
elif n == 6:
print("...../")
annoying_valley(5)
print(".....\\")
else :
print("." * (n - 1) + "/")
annoying_valley(n - 1)
print("." * (n - 1) + "\\")
def annoying_int_sequence(n):
"""This Function prints a recursive series whose base series is [1,2,1]
It takes a input number (n)
It returns a List of integers
The input number must be >= 0 to see the output
The functions returns a list which will repeat till(n-1) times and after that [n] will be printed.
Example:
For(n=3) The final return will be [1,2,1] * (3-1) + [1,2,1]. Here [1,2,1] is variable a = [1,2,1]
"""
if n == 0:
return []
elif n == 1:
return [1]
else :
a = annoying_int_sequence(n - 1)
b = a + [n]
return b * (n - 1) + a
I hope you have understood
the solution. If you like the solution kindly upvote
it.