Fraction Simplifier

This challenge consists of writing a program that asks the end-user to enter a fraction (numerator and denominator) and output the matching reduced fraction when the fraction can be reduced.

To see what this program should do in action you may want to try fractionsimplifier.com.

fraction_numerator_denominator

To simplify a fraction your program will need to find the greatest common divisor (aka greatest common factor) of the numerator and denominator that will have been entered by the end user. Then, your program will divide the numerator and denominator of the fraction by this number.

fraction

To find out if a number is a factor of the numerator you will need to check that the remainder of the numerator divided by this number is null (=0):

  • For instance 3 is a factor of 24 because 24 mod 3 = 0.
  • remainder_24

  • Whereas 5 is NOT a factor of 32 because 32 mod 5 = 2 != 0.
  • remainder32

Extra tip: A factor of a number is always lower or equal to this number.

Your Challenge:


Complete the code below to find the greatest common factor of both the numerator and denominator entered by the end-user and use it to output the simplified fraction.

Share Button
Posted in Computer Science, Python - Advanced, Python Challenges Tagged with: ,

Our Latest Book

Follow this blog