Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to simplify fraction in python

def gcd(a,b):
	if a == 0:
		return b
	if b == 0:
		return a
	if a == b:
		return a
	if a > b:
		return gcd(a-b, b)
	return gcd(a, b-a)

def simplifyFraction(a, b):
  divisor = gcd(a, b)
  return (a / divisor, b / divisor)
 
PREVIOUS NEXT
Tagged: #simplify #fraction #python
ADD COMMENT
Topic
Name
3+6 =