0

im a beginner in python, can somebody help me what i did wrong here?

import math def quadratgleichung(a,b,c): loesung1 = - (b/a)/2 + sqrt( ((b/a)/2) * ((b/a)/2) - (c/a) ) loesung2 = - (b/a)/2 - sqrt( ((b/a)/2) * ((b/a)/2) - (c/a) ) return loesung1, loesung2 a = input("Enter a.") b = input("Enter b.") c = input("Enter c.") quadratgleichung(a,b,c) print(f"Die Lösungen der eingegebenen quadratischen Gleichung sind {loesung1} und {loesung2} !\n") 

this is what comes out in the console: should i use different variable names in the function or were is the problem?

TypeError Traceback (most recent call last) <ipython-input-11-3207ceaf35b6> in <module> 12 c = input("Enter c.") 13 ---> 14 quadratgleichung(a,b,c) 15 16 print(f"Die Lösungen der eingegebenen quadratischen Gleichung sind {loesung1} und {loesung2} !\n") <ipython-input-11-3207ceaf35b6> in quadratgleichung(a, b, c) 3 4 def quadratgleichung(a,b,c): ----> 5 loesung1 = - (b/a)/2 + sqrt(((b/a)/2) * ((b/a)/2) - (c/a)) 6 loesung2 = - (b/a)/2 - sqrt(((b/a)/2) * ((b/a)/2) - (c/a)) 7 TypeError: unsupported operand type(s) for /: 'str' and 'str' 

thanks in advance!!

2

1 Answer 1

1

Just by looking at the error, it looks like the variables a, b and c get sent as a string. Then your quadratgleichung method is trying to divide the string types, which it can't do.
Try to convert the a, b, and c to float before calling the quadratgleichung
a = float(input("Enter a.")) and the same for b and c

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.