Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Greatest Common Factor (Euclidean algorithm, aka Euclid's algorithm)
def GCF(n1,n2): '''Finds the greatest common factor between two numbers using the Euclidean algorithm, aka Euclid's algorithm''' '''Author:Wazim Karim''' dividend = max(n1,n2) #dividend is bigger of two numbers divisor=min(n1,n2) #divisor is smaller of two numbers remainder=dividend%divisor #calculate the remainder if remainder == 0: return divisor #if divisor goes into dividend with no remainder, GCF is divisor while remainder != 0: #so long as the divisor does not go into dividend without a remainder dividend=divisor #the divisor becomes the dividend divisor=remainder #the remainder becomes the divisor remainder = dividend%divisor #calculate the reminder if remainder == 0: #if divisor goes into dividend with no remainder, GCF is divisor return divisor #so return the divisor #gcf of two numbers: print(GCF(30,15)) #gcf of more than 2 numbers by nesting: print(GCF(GCF(128,GCF(32,12)),2))
run
|
edit
|
history
|
help
0
hahahah
Linear Regression Python
abstractmethod
PySlots3
Decimal, Octal, Hexadecimal and Binary Format
PyDescript
Keygen for 010 Editor
Swastik pattern
Assignment-2b
Rishika