+ 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

21st Jun 2020, 5:32 PM
OSΔSℱ
OSΔSℱ - avatar
6 Respostas
+ 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.
21st Jun 2020, 6:26 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 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 :)
22nd Jun 2020, 9:40 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 1
Thank u very much Mr Kuba SiekierzyƄski , it's Well understood
22nd Jun 2020, 3:47 PM
OSΔSℱ
OSΔSℱ - avatar
0
~ swim ~ I'm Sorry, I've inserted it.
21st Jun 2020, 7:21 PM
OSΔSℱ
OSΔSℱ - avatar
0
Mr Kuba SiekierzyƄski, Thank You but I don't understand the Complex Numbers. Can you break it down to beginner's level.
21st Jun 2020, 7:25 PM
OSΔSℱ
OSΔSℱ - avatar