In this challenge we are going to use an easy hack to quickly compare two fractions without having to calculate their decimal value.

For instance, can you quickly tell which of the following two fractions is bigger?

#### Fraction Hack: The Butterfly method!

Here is our quick approach to compare two fractions. It is called the **butterfly metho**d and is based on performing a cross-multiplication as follows:

The butterfly method is used to calculate the cross-products of our two fractions. By comparing these cross-products we can then deduct how both fractions compare:

#### Python Task

Your task is to write a Python program that will:

- Ask the user for to enter four values: the numerators and denominators of two fractions.
- Use the butterfly method to calculate and compare the cross products of these two fractions.
- Compare the cross products to decide which fraction is bigger and output a clear message on screen.
- Calculate and output the decimal values of both fractions to help the user confirm the outcome of the Butterfly method.

#### Python Code

#### Test Plan

Test # | Input Values | Expected Output | Actual Output |

#1 | 7/10 and 5/8 | 7/10 > 5/8 | |

#2 | 7/10 and 9/12 | 7/10 < 9/12 | |

#3 | 7/10 and 21/30 | 7/10 = 21/30 | |

#4 | 7/10 and 18/25 | 7/10 < 18/25 |

#### Solution...

The solution for this challenge is available to full members!Find out how to become a member:

➤ Members' Area

#### Solution...

The solution for this challenge is available to full members!Find out how to become a member:

➤ Members' Area

#### Solution...

You are viewing this solution as part of your full membership subscription!Initial Challenge

#### Python Code

#Maths Fraction Hack Algorithm - www.101computing.net/maths-fraction-hack-algorithm/ a = int(input("Enter the numerator of the first fraction:")) b = int(input("Enter the denominator of the first fraction:")) print("First Fraction: " + str(a) + "/" + str(b)) # 1 - Complete the code here to enter the second fraction c = int(input("Enter the numerator of the second fraction:")) d = int(input("Enter the denominator of the second fraction:")) print("Second Fraction: " + str(c) + "/" + str(d)) # 2 - Complete the code here to calculate and compare the cross-products. Output which fraction is bigger product1 = a*d product2 = b*c if product1 > product2: print("The first fraction is bigger than the second one.") elif product1 < product2: print("The second fraction is bigger than the first one.") else: print("Both fractions are equivalent!") # 3 - Complete the code here to output the decimal value of both fractions print("First Fraction: " + str(a) + "/" + str(b) + " = " + str(a/b)) print("Second Fraction: " + str(c) + "/" + str(d) + " = " + str(c/d))