(This is how it should appear when I run it.) a = 3; b = 5; c = 4 There are no solutions
So far I have this set up in python and I do not know what I am doing wrong. (note: my professor wants us to call main at the end of the define functions)
import math
import sys
def main():
print("a = ",a,";b = ",b,";c = ",c,)
print_quadratic_solution(3, 5, 2)
a = print_quadratic_solution(a)
b = print_quadratic_solution(b)
c = print_quadratic_solution(c)
def print_quadratic_solution(a, b, c):
a = int(a)
b = int(b)
c = int(c)
discriminant = b**2 - 4*a*c
if discriminant < 0:
print("There are no solutions.")
elif discriminant == 0:
x = (-b + math.sqrt(discriminant)) / (2*a)
print("There is a double root at", x)
elif discriminant > 0:
x1 = (-b + math.sqrt(discriminant)) / (2*a)
x2 = (-b - math.sqrt(discriminant)) / (2*a)
print("The first root is", x1, " and the second is", x2, ".")
main()
The results come out like this:
The first root is -0.6666666666666666 and the second is -1.0 .
Traceback (most recent call last):
File "C:\Users\Juan1\Documents\Computer Science 1300\EliAssignment6.py", line 23, in <module>
main()
File "C:\Users\Juan1\Documents\Computer Science 1300\EliAssignment6.py", line 5, in main
print("a = ",a,";b = ",b,";c = ",c,)
NameError: name 'a' is not defined
So can someone help me?