1. Engineering
  2. Computer Science
  3. making your function more flexible now the above function is...

Question: making your function more flexible now the above function is...

Question details

Making your function more flexible Now, the above function is great for computing x, but what if I wanted a function that could more generally compute the values for a list of x -values raised to any power? As a group, design a small function called compute_exponent that satisfies the following 1. Given a list of x-values, it computes the value of x for each value, where a is a parameter that is fed into your function. 2. The default value of a is 2 3. It returns the list of all the x values. Make sure you print out the list of resulting values to confirm that your code is working. Run your function for a variety of input values. In [ ]: # WRITE PSEUDO-CODE HERE (in the form of comments) In [9]: | # Put your code here def compute_exponent (a,n): compute the exponent of agivenn if n<-1: return a else: return (a*compute_exponent (a,n-1)) res -compute_exponent (10,2) print(res) 100 Question: What happens in your function if a 0.5 and your x -values are a combination of positive and negative numbers? Put your answer here Question: What if you only wanted your function to return a list of new values if all of the values are non-imaginary numbers? Explain how you might re-write your code to accomplish this. You should brainstorms ideas with your group! In case you dont remember what imaginary numbers are: https://en.wikipedia.org/wiki/Imaginary number Put your answer here

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution