Question: (PYTHON) a) Write a function named mersenne() that takes as input a number n and outputs the number 2 n -1. These are called Mersenne

(PYTHON)

a) Write a function named mersenne() that takes as input a number n and outputs the number 2n-1. These are called Mersenne numbers*. For example, the second Mersenne number is 22-1 = 3, the fifth Mersenne number is 25-1 = 31, and the nineteenth Mersenne number is 219-1 = 524287.

Hint: This is a pure function. So if print() or input() appear in the function definition, then the problem will be rejected.

b) Write a script that includes the definition of mersenne() that you just wrote. When the script is executed, it should ask the user to input 3 numbers and then use themersenne() function to print out the corresponding 3 Mersenne numbers. So if the user types in 2, 5, and 19, the script will display (on the screen) something like Your Mersenne numbers are 3, 31, and 524287.

Hint 1: The script you write here should use both input() and print() because the instructions specifically mention taking input from the user and displaying results on the screen.

Hint 2: You should be using the function you wrote in part (a), not copying it. The only place that arithmetic operators (like - and **) should appear is inside the definition you wrote in part (a). Instead of repeating the arithmetic, you should be using the function you just wrote.

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!