Assignment 05
Assignment 05
Programming Assignment 05
-
Functions
Instructions
The autograder will evaluate your code for a few testcases. If some testcases fail, the
autograder should show you what is your code output, and what is the expected output.
The autograder will give you a score based on the testcases, but a grader will manually
evaluate your coding style after the deadline. Style represents 30% of the coding assignment
grade.
Write the function greatest_common_divisor (in the file exercise1.py) that does the
following.
Function reduce_fraction(n, m)
• takes 2 parameters n, m → type int that , respectively, represent the numerator and
denominator of a fraction as its only two parameters.
• calls an other function greatest_common_divisor and use the returned value to reduce
the fraction to its lowest terms.
• returns the numerator and denominator of the reduced function if the function can be
reduced or the original numerator and denominator if the function cannot be reduced
→ type int
Then, write a program ( in the main() in the file exercise1.py) that does the following.
Program main()
Sample examples (the user input is in red, the printed output is in blue, and the prompt is in black):
Enter the numerator: > 96 Enter the numerator: > 91
Enter the denominator: > 36 Enter the denominator: > 17
The fraction 96/36 can be reduced The fraction 91/17 cannot be
to 8/3 reduced
Write the function proper_divisors (in the file exercise2.py) that does the following:
Function proper_divisors(N)
An integer, N, is said to be perfect when the sum of all of the proper divisors of N is equal to
N. For example, 28 is a perfect number because its proper divisors are 1, 2, 4, 7 and 14, and 1 + 2
+ 4 + 7 + 14 = 28.
Write the function perfect_number (in the file exercise2.py) that does the following:
Function perfect_number(N)
Then, write a program ( in the main() in the file exercise2.py) that does the following.
Program main()