Skip to content

Instantly share code, notes, and snippets.

@reuf
Created September 27, 2015 18:44
Show Gist options
  • Save reuf/f39776f3e0e65984a52d to your computer and use it in GitHub Desktop.
Save reuf/f39776f3e0e65984a52d to your computer and use it in GitHub Desktop.
Basic algos and math solvers
__author__ = 'user'
def fibonocci_sequence():
a, b = 0, 1
while b<100:
print(b)
a, b = b, a+b
fibonocci_sequence()
def prime_numbers():
for i in range(2,20):
for j in range (2,i):
if i%j == 0:
print (i, 'equals', j, '*', i//j)
break
else:
print(i, 'is a prime number')
def even_odd_num():
for i in range (1,100):
if i%2 == 0:
print (i, 'is even number')
else:
print (i, 'is odd number')
even_odd_num()
def divisible_by_3_or_5():
for i in range(1,100):
if i%3 == 0 and i%5 == 0:
print(i,' is divisible by 3 and by 5')
elif i%3 == 0:
print(i,' is divisible by 3')
elif i%5 == 0:
print(i,' is divisible by 5')
else:
print(i,'-----')
divisible_by_3_or_5()
def quadratic_equation():
import math
a,b,c = 1.0,-7.0,12.0
det = math.pow(b,2)-4*a*c
print ("det = "+str(det))
if det < 0:
print("Ne postoje rijesenje za te parametre")
elif det == 0:
x1, x2 = -b/(2*a), -b/(2*a)
print("x1 = "+ str(x1))
print("\n")
print("x2 = "+ str(x2))
elif det > 0:
x1, x2 = (-b+math.sqrt(det))/(2*a), (-b-math.sqrt(det))/(2*a)
print("x1 = "+ str(x1))
print("\n")
print("x2 = "+ str(x2))
quadratic_equation()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment