+ 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
5 odpowiedzi
+ 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