#def pf(n,d): #Prime factorisation n=input() d=input() a = n b = d primes = [2, 3, 5, 7, 9, 11, 13, 17, 19, 23, 29, 31, 37] factora = [] factorb = [] count = 0 divideby = 1 while count < len(primes) : divide = primes[count] while int (a/divide) == (a/divide) : a = (a/divide) factora.append(divide) count = (count+1) print(factora) count = 0 while count < len(primes) : divide = primes[count] while int (b/divide) == (b/divide) : b = (b/divide) factorb.append(divide) count = (count+1) print(factorb) hcf = [val for val in factora if val in factorb] print(hcf) count = 0 while count < len(hcf) : divideby = (divideby * hcf[count]) count = (count+1) print("Fraction entered was ", int(n), "/", int(d)) print("Fraction cancels to ",int(n/divideby),"/",int(d/divideby))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question