Uma brincadeira com bhask-sei-lá-quem-indiano e as equações de 2o grau, pra explicar python prum amigo aí ;D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a * x**2 + b * x + c = 0, a != 0 | |
# (-b +- sqrt(d) ) / 2 * a | |
# d = b**2 - 4 * a * c | |
from math import sqrt | |
#print 3 ** 2 | |
#print sqrt(9) | |
def get_d(a, b, c): | |
return ( b ** 2 ) - ( 4 * a * c ) | |
def get_bsk(a, b, d): | |
return [ ( -b + sqrt(d) ) / ( 2 * a ), ( -b - sqrt(d) ) / ( 2 * a ) ] | |
def solve_eq(a, b, c): | |
d = get_d(a, b, c) | |
print "[x, x'] = ", get_bsk(a, b, d) | |
a = 1 | |
b = -4 | |
c = 3 | |
solve_eq(a, b, c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment