Stack Exchange
Quadratic equation: TypeError: bad operand type for unary -: 'str'
I´m new to Python and have been trying to code the quadratic equation, but i keep running into this error:
TypeError: bad operand type for unary -: 'str'
def quad_gleichung():
a = input('a:')
b = input('b:')
c = input('c:')

x1 = int(-b + (b**2 - (4*a*c))**(0.5)) / (2*a)
x2 = int(-b - (b**2 - (4*a*c))**(0.5)) / (2*a)


print('Lösung 1:', x1)
print('Lösung 2:', x2)

quad_gleichung()

Can anyone please help me?
Thanks!

Convert your input to a number type!

The return type of input is string. It needs to be converted to some number type, float or int, depending on use case.
Therefore, change the assignments to a, b, c to:
a = int(input("a: ")) # or float(input("a: "))
b = int(input("b: ")) # or float(input("b: "))
c = int(input("c: ")) # or float(input("c: "))


With this "solution" you have to hope that the user only inputs digits

@BrutusForcus: that's right, but I guess in this case we can assume one will. Of course you could do some other fancy stuff, but that's the simplest one. One could also surround everything with try except or something else.
