Before completing this challenge we need to revise some Maths concepts.
Fraction = numerator / denominator
In Maths a fraction consists of two numbers: a numerator and a denominator.
What is an improper fraction?
An improper fraction is a fraction where the numerator is greater than or equal to the denominator.
7⁄4, 12⁄10, 21⁄3 are all improper fractions.
What is a proper fraction?
A proper fraction is a fraction where the numerator is lower than to the denominator.
7⁄9, 12⁄21, 3⁄4 are all proper fractions.
What is a mixed number?
A mixed number is a number consisting of a whole number and a proper fraction.
31⁄2, 13⁄10, 213⁄4 are all mixed numbers.
Converting improper fractions into mixed numbers
We can easily convert an improper fraction into a mixed number by calculating the quotient and the remainder from the improper fraction.
Mixed number = Quotient Remainder⁄Denominator
For instance: Let’s convert 11⁄4 into a mixed number
Step 1: Quotient (Whole Division): 11 DIV 4 = 2
Step 2: Remainder: 11 MOD 4 = 3
11⁄4 = 2 3⁄4
Quotient & Remainder in Python?
In Python you can use the // operator to calculate the quotient of a fraction and the % operator to calculate the remainder of a fraction.
quotient = 11 // 4
remainder = 11 % 4
Python Challenge #1
Complete the code given below to convert an improper fraction into a mixed number by:
- Check that the user has entered a numerator and a denominator for an improper fraction. (The numerator should be greater or equal to the denominator).
- Calculate and display the mixed number corresponding to the given fraction.
Python Challenge #2
Create a Python script to convert a mixed number into an improper fraction.