#WEEKLY Challenges 1: Fractions solution
For this first weekly challenges, my solution uses fractions to solve the problem.
My Solution uses how division of fractions works. Dividing two fractions is the same as multiplying the first fraction by the reciprocal of the second fraction. This means that I can do the opposite: multiply fractions by following the same steps and dividing.
This project uses the python standard library module
To convert a given number
n to a fraction, I use two rules. 1. If
n is a whole number, its fraction can be
2. Otherwise for decimals, I take the whole part and the decimal part strings, concatenate them (this avoids using multiplication) and set them over 10 raised to the length of the decimal part. To create this power of 10 I use simple string concatenation ("1" plus "0" times the power) since I know it will always be positive.
Once I have the two fractions I check that they're the same as their decimal version to make sure there are no errors. Then, I flip the second fraction and divide.
I have a main function that will prompt the user for input, run my function, and then check if it was correct!
This is an original solution not copied from anywhere.