python:py_lists:py_code:math
Math Algorithms
| FizzBuzz Math Algorithm |
|---|
def fizzbuzz(n):
for i in range(1, n + 1):
if i % 3 == 0 and i % 5 == 0:
print('FizzBuzz')
elif i % 3 == 0:
print('Fizz')
elif i % 5 == 0:
print('Buzz')
else:
print(i)
|
| GCF Greatest Common Factor Math Algorithm |
def gcf(i1, i2):
gcf = None
if i1 > i2:
smaller = i2
else:
smaller = i1
for i in range(1, smaller + 1):
if i1 % i == 0 and i2 % i == 0:
gcf = i
return gcf
gcf(20, 12)
|
| Euclids Algorithm |
def gcf(x, y):
if y == 0:
x, y = y, x
while y != 0:
x, y = y, x % y
return x
|
| Prime Number Algorithm |
def is_prime(n):
for i in range(2, n):
if n % i == 0:
return False
return True
|
| XX String Algorithm |
| XX String Algorithm |
| XX String Algorithm |
python/py_lists/py_code/math.txt · Last modified: by adminguide
