forked from Aneesh540/python-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFraction-reduce.py
More file actions
36 lines (28 loc) · 766 Bytes
/
Fraction-reduce.py
File metadata and controls
36 lines (28 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""How to extract data from Fraction class(is is not callable) but
__mul__ method is defined
>>> Fractions(1,2)*Fractions(3,4)
>>> Fractions(3,8)
>>> print(Fraction(6,8))
>>> 3/4
>>> t=Fraction(1,2)
>>> t.numerator
>>> 1
>>> t.denominator
>>> 2
"""
from fractions import Fraction
from functools import reduce
def product(fracs):
t=reduce(lambda x,y:x*y , fracs)
# now t is a instance of Fraction bcoz recude'll return a single class
return t.numerator, t.denominator
if __name__ == '__main__':
fracs = []
for _ in range(int(input())):
fracs.append(Fraction(*map(int, input().split())))
print(fracs)
result = product(fracs)
print(*result)
# x=1,2,3,4
# print(*x) prints all value in one line
# 1 2 3 4