+ 2
What's wrong with this Code
My Quadratic Calculator can't solve with negative or/and large Numbers https://code.sololearn.com/cAjmnfFzaHkr/?ref=app
6 Antworten
+ 7
OSΔS™ Is this the code?
https://code.sololearn.com/cAjmnfFzaHkr/?ref=app
You check all the numbers for isdigit(). This makes all negative numbers return False here (as the minus is not considered a digit).
Also, it's not the large numbers that fail your code -- if you give all positive integers, the quadratic equation does not have a solution in real numbers. It returns solution in complex numbers, while you want all your solutions to be integers.
+ 7
OSΔS™ In your equation, where you have √(b² - 4ac) --> if b² < 4ac the quadratic function has no solution, it does not cross the X axis anywhere (there is no square root of a negative number). This is why you have an error.
My advice - either add an if statement that checks for that and print "No solution" right away or include a try/except clause catching the ValueError and print "No solution" then.
Well, or... switch to complex numbers :)
+ 1
Thank u very much Mr Kuba Siekierzyński , it's Well understood
0
~ swim ~ I'm Sorry, I've inserted it.
0
Mr Kuba Siekierzyński, Thank You but I don't understand the Complex Numbers. Can you break it down to beginner's level.