Write and test a iterative function that determines the


Assignment

Task 1

Write and test a iterative function that determines the greatest common divisor (GCD) of two numbers.

Requirements

• Name your function gcd. Your function must take two parameters. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• Write a test function called test gcd that tests your gcd function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. Choose inputs that test different aspects of your function. For example, you may have one test gcd(5,5), that checks that the function works properly when the inputs are both positive and the same value. Once you have this test, you do not need another test gcd(8,8), as this checks the same thing. You should not use any tests involving inputs that are not integers.

Task 2

Write and test a iterative function that determines the least common multiple, lcm, Of two numbers.

Requirements

• Name your function lcm. Your function must take two parameters. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• Write a test function called test lcm that tests your lcm function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. You should not use any tests involving inputs that are not integers.

Task 3

Write and test a iterative function that determines a number raised to a power, pow.

Requirements

• Name your function pow. Your function must take two parameters; a number and the power it is to be raised to. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• Write a test function called test pow that tests your pow function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. You should not use any tests involving inputs that are not integers.

Task 4

Write and test a iterative function that determines if the first number is a factor of the second number, is factor. It will return a True or False answer.

Requirements

• Name your function is factor . Your function must take two parameters; a number and the number to see if it is a factor of. You may assume that the inputs provided to your function are integer values. That is, you do not need to do any error-checking to confirm that they are integer values.

• You must user iteration. The usage of modulo it prohibited in this function.

• Write a test function called test is factor that tests your is factor function by calling it several times with different inputs. You should have at least six (and perhaps more) tests. You should not use any tests involving inputs that are not integers.

Task 5

Write a main function to allow a user to select and run one of the functions above.

The function should display the available functions to the user and allow then to input one to select. Then based on the function selected it should prompt the user for the required function inputs.

Example Operation:
List of functions

1. POW
2. GCD
3. LCM
4. is_factor

Please select a function: 1

Please enter the base: 2 Please enter the exponent: 3

The 2 raised to the 3 power is 8

6 Programming Tips

Modulo

Python provides an operator that computes the remainder when one number is divided by another. It is very useful - we will see it again in this course! It is called the modulo operator. From the interactive console:

>>> 8 3
2
>>> 4 11
4
>>> 60 5
0

Simple print Formatting

Normally, if you execute a print statement like

print( 5, "x", 2 ) your output looks like 5 x 2

If you want there to be no spaces between the values printed, add a value for a special, named parameter sep:

print( 5, "x", 2, sep="" )

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Write and test a iterative function that determines the
Reference No:- TGS02659985

Expected delivery within 24 Hours