Question
import math def reduce(x): g = math.gcd(x[0],x[1]) return (int(x[0]/g),int(x[1]/g)) ###LOOK Use //, not / def add(x,y): num = x[0]*y[1] + x[1]*y[0] dem = x[1]*y[1] return
import math
def reduce(x): g = math.gcd(x[0],x[1]) return (int(x[0]/g),int(x[1]/g)) ###LOOK Use //, not /
def add(x,y): num = x[0]*y[1] + x[1]*y[0] dem = x[1]*y[1] return (num,dem)
def multipy(x,y): ###LOOK mpy, not multiply return (x[0]*y[0],x[1]*y[1])
if __name__=='__main__': print('Fraction caculator') #main will run until you press 0 print("0. break") while (True): #print(' ----You can press 0 to exit----') ###LOOK WHERE did this code, just below, come from? f1 = tuple([int(x) for x in input("Enter a fraction>>>").split("/")]) ###LOOK WHY is this next line not indented properly? ###LOOK It is supposed to be WITHIN the while loop f2 = tuple([int(x) for x in input("Enter a fraction>>>").split("/")]) ###LOOK all the code from here down should be WITHIN the while loop ###LOOK Your indentation is incorrect -- it all needs to be indented r1=reduce(f1) r2=reduce(f2)
s = reduce(add(r1,r2)) print("Sum of the fractions: %d/%d "%(s[0],s[1])) m = reduce(multipy(r1,r2)) print("Multiplication of the fractions: %d/%d "%(m[0],m[1])) ###LOOK What is 'option'? Where does it get a value? # Loop continuously # Get the input if f1 == "": # If it is a blank line... break
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started