im trying to write a code that i can input a,b,c and the code will run it in the quadratic formula and give me the answer but i keep getting a error problem

import math
from math import sqrt

print
print ("Welcome to the Quadratic Program")
print ("--------------------------------")
print

a=input("Enter a: ")
b=input("Enter b: ")
c=input("Enter c: ")

print
print

answer=[b+(math.sqrt((b*b)-(4*a*c)))]/(2*a)
if answer<0:
print ("negative")
print answer

Recommended Answers

All 2 Replies

I think you use python 3?
In python 3 input() return a string.
And formula will not work.
You can try this,and use code-tag also post error message(Traceback)

import cmath

print("Welcome to the Quadratic Program")
print("--------------------------------")

a = int(input("Enter a: "))
b = int(input("Enter b: "))
c = int(input("Enter c: "))

answer = (-b + cmath.sqrt(b ** 2 - 4 * a * c)) / 2
print(answer)

thank you, the code works great,
i have another question, the answer is printed in (-.05+0j) format, is there a way for the program to print just the answer without the j ?

**Nevermind i got it, i changed from "cmath" to "math", thanks for everything

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.