← Back to challenges

Simplifying to Simplest Ratio

PythonHardmathstringsnumbers

Instructions

Create a function which simplifies a given fraction into its simplest ratio. Return the fraction as a string.

Examples

simplify_frac("2/4") ➞ "1/2"

simplify_frac("15/25") ➞ "3/5"

simplify_frac("4/9") ➞ "4/9"

Notes

  • Fractions are given as strings.
  • Return the same fraction if it is already in its simplified ratio (see example #3).
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.