Expressing my doubt that you will actually need to process strings of compound tuples, the solution you are looking for is raw_input
(instead of input
), and ast
(which is what input
does).
Now, when the two tuples are understood separately, the program may now process numbers with more than two digits.
import ast
def mult(num):
sep_indx = num.find(')(')
assert sep_indx > -1
tuple1, tuple2 = num[:sep_indx+1], num[sep_indx+1:]
tuple1 = ast.literal_eval(tuple1)
tuple2 = ast.literal_eval(tuple2)
numn=int(tuple1[0])
denom=int(tuple1[1])
numn1=int(tuple2[0])
denom1=int(tuple2[1])
numnetor=numn*numn1
denominetor=denom * denom1
ans=str(numnetor)+'/'+ str(denominetor)
return ans
askUser=raw_input("Enter Fraction:")
print(mult(askUser))
#Enter Fraction:(1,20)(3,40)
#3/800
Do note that your program will still have problems with division by zero errors, issue with extra spaces, and any non-integer numbers entered by the user. I am leaving these to you.