Question: PYTHON A. Write a function called collatz() that takes a number and checks whether it's even or odd. If it's even, the function should return

PYTHON

A. Write a function called collatz() that takes a number and checks whether it's even or odd. If it's even, the function should return half the number. If it's odd, it should return one more than three times the number.

B. If you take an output of the collatz() function and feed the result back into collatz() and then take that result and feed it back into the function again, and if you keep repeating that process over and over again, you will eventually end up with the number 1. Sometimes it only takes one step, as in collatz(2), which immediately returns 1. Sometimes it takes two steps: collatz(collatz(4)) also returns 1. And sometimes it takes quite a few more: collatz(collatz(collatz(collatz(collatz(5))))) returns 1 as well. Play around with different numbers in the interactive shell like this until you find a number that requires at least 5 applications of collatz() before it gets down to 1. Make sure you do the repeated applications all in one line, like the examples I listed above. After you've found one that takes at least 5 applications

REMEMBER TO INCLUDE A DOCSTRING WITH A PURPOSE STATEMENT AND SIGNATURE FOR ALL YOUR FUNCTION DEFINITIONS.

C. Write a function (call it numbersize1()) that takes a number as an argument, and returns the string 'Negative!' if the number is less than zero, 'Small!' if the number is at least zero but less than 10, 'Medium!' if the number is at least 10 but less than 100, and 'Large!' if the number is greater than or equal to 100. Do this only using if statements, and do not use else or elif.

D.Write a function (called numbersize2()) that does the exact same thing as numbersize1(), but uses three nested if...else statements. Do not use elif for this one.

E. Write a function (called numbersize3()) that does the exact same thing as numbersize1(), but uses exactly one if-elif-else statement. (You can use the elif keyword more than once, but only one if and only one else.)

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!