0

# How to make ratio in python

Like puting two integers and rationing them like x=12 y=6 ratio 4:3 output = 3:2

3 Answers

+ 2

You would need to get their common factors.
You can represent integers by the product of the factors of the integer.
You could represent:
4 as: 2 * 2
6 as: 2 * 3
9 as: 3 * 3
10 as: 2 * 5
100 as: 2 * 2 * 5 * 5
10's and 100's common factors could be 2 and 5.
To simplify 10/100
You would need to take all the common factors from both integers (if other side gets left without factors, put 1):
(2 * 5) / (2 * 2 * 5 * 5)
() / (2 * 5)
1 / (2 * 5)
10 / 100 would be simplified to 1 / 10.
36 / 81:
(2 * 2 * 3 * 3) / (3 * 3 * 3 * 3)
(2 * 2) / (3 * 3)
4/9

+ 2

You can use the fractions library to work with rational numbers.
https://code.sololearn.com/c1UX6FN7LUBL/?ref=app

0

Seb S i guess yohr right