Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Implement fun_math.py In this problem, you will use functions to perform some simple mathematical computations. Any mathematical background or information that you may need

2. Implement fun_math.py

In this problem, you will use functions to perform some simple mathematical computations. Any mathematical background or information that you may need is provided to you.

2a. Generate Cullen Numbers (2 points)

Cullen numbers are integers of the form 2+1n2n+1 where n is an integer.

Your task is to implement a function with the following signature:

def cullen(n:int) -> int 

The function should take as input an integer n and return the corresponding Cullen Number.

Example:

cullen(1) # This should return 3 cullen(5) # This should return 161 

2b. Generate Woodall Numbers (2 points)

Woodall numbers are integers of the form 21n2n1 where n is an integer.

Your task is to implement a function with the following signature:

def woodall(n:int) -> int 

The function should take as input an integer n and return the corresponding Woodall Number.

Example:

woodall(1) # This should return 1 woodall(5) # This should return 159 

2c. Generate Fermat Numbers (2 points)

Fermat Numbers are integers of the form 22+122n+1 where n is an integer.

Your task is to implement a function with the following signature:

def fermat(n:int) -> int 

The function should take as input an integer n and return the corresponding Fermat Number.

Example:

fermat(1) # This should return 5 fermat(2) # This should return 17 

2d. Divisibility (2 points)

An integer a is said be divisible by another integer b if a when divided by b leaves no remainder. For instance, 1212 is divisible by 33 but not by 55.

Your task is to implement a function with the following signature:

def divides_evenly(dividend:int, divisor:int) -> bool 

The function should take as input two integers, the dividend and the divisor and returns whether the dividend is divisible by the divisor or not.

Example:

divides_evenly(10, 5) # This should return True divides_evenly(10, 3) # This should return False 

2e. Square Numbers (3 points)

A square number or perfect square is an integer that is the product of some integer with itself. For instance, 99 is a square number since 32=932=9 but 55 is not.

Your task is to implement a function with the following signature:

def is_square(n:int) -> bool 

The function should take as input an integer n and returns whether the n is a square number or not.

Example:

is_square(100) # This should return True is_square(97) # This should return False

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

Step: 3

blur-text-image

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

Professional Visual Basic 6 Databases

Authors: Charles Williams

1st Edition

1861002025, 978-1861002020

More Books

Students also viewed these Databases questions