Question: 1. Write a program that contains the recursive functions below (please note for all the functions, you must use recursion and not loops or
1. Write a program that contains the recursive functions below (please note for all the functions, you must use recursion and not loops or built in Python functions): a. def power(x, y): This function should recursively compute the power of a number (x represents the number and y represents the power to which its being raised - assume y will always be a positive integer) e.g., # 2 = 8 #-2 = -8 # 15 = 1 i. print(power(2, 3)) ii. print(power(-2, 3)) iii. print(power(1,5)) b. def cat_cars(n): If every cat has 2 ears, this function should recursively compute the total number of ears based off the number of cats (n represents the total number of cats) e.g., i. print(cat_ears(0)) #0-0 cats have 0 ears in total ii. print(cat_ears(1)) #2-1 cat has 2 ears in total iii.print(cat_cars (2)) #4-2 cats have 4 ears in total c. def alien_ears(n): We have aliens standing in a line, numbered 1, 2, ... The odd aliens (1, 3, ...) have 3 ears. The even aliens (2, 4, ...) have 2 ears. This function should return the total number of alien ears (n represents the total number of aliens) e.g., i. print(alien_ears(1)) ii.print(alien_ears(2)) #3 - (alien 1 has 3 cars) #5 - (alien 1 has 3 ears, alien 2 has 2 ears)
Step by Step Solution
There are 3 Steps involved in it
Below is a stepbystep explanation of the recursive functions power cat ears and alien ears implemented in Python 1 Power Function powerxy This function is designed to compute the power of a number x r... View full answer
Get step-by-step solutions from verified subject matter experts
