usingMaths.com
Demonstrating and showing pupils and students one application of Mathematics.







<< Previous Next >>

Code for Multiplying Fractions in Python



Method of Multiplying Fractions

Multiplying fractions is pretty straightforward:
Cancel out all common factors between numerators and denominators, then multiply whatever is left numerator to numerator and denominator to denominator.


Algorithm Steps to Multiply Fractions in Python:

If we have
                  4/9 x 21/8;

Step 1:

Find any common factor between any numerator and any denominator.

Step 2:

Cancel out any such common factor.

= X7
421
98
3 
Step 3:

Repeat Steps 1 & 2 recursively until there are no more common factors.

=1X 
47
38
 2
=7
6

Create a new module file; call it MultiplyFraction.py. Type out the adjoining Python code for multiplying fractions.



Note: You can comment out the LowestTerm Python object code in the main class from the previous lesson or simply continue from where it stopped.


So!

Feel free to try out your own set of numerators and denominators for fractional multiplication.









<< Previous Next >>