Question: Python 1. Define a function no_negatives that takes a single argument x, returning the value ^2+53. However, if the function is called with a negative

Python

1. Define a function no_negatives that takes a single argument x, returning the value ^2+53. However, if the function is called with a negative value of x, it should instead return the value None. Implement this without using either else or elif!

2. Define a function smaller_abs_root that takes three arguments a, b, and c, calculates the two roots of the quadratic equation ax^2+bx+c=0. If both roots are positive, it should print out "two positive roots"; if only one root is positive, it should print out "one positive root"; if neither is positive, it should print out "no positive roots". Then, it should return whichever of the two roots has the smaller absolute value. (You may assume it will only be called with values that result in real roots.)

3. Define a function named f2 that implements the exact same function as f1 above. However, f2 should take an additional optional argument named debug whose default value is False. If the function is called without specifying a value for this, or explicitly specifying that its value is False, the function should operate just as f1 does. However, if a value of True is supplied for this argument, the function should use a print function to display "f2 called with x = xxx and n = nnn", where "xxx" and "nnn" are replaced by the numerical values of x and n that the function was called with.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!