Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

Students also viewed these Databases questions

Question

=+number of people to achieve the business plan?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago