00:01
Today, we're looking love at problem number 4 .1, quadratic equations from the wonderful python textbook.
00:11
And in this problem, we're basically asked to write a program to solve a quadratic equation.
00:25
So what should this program entail? so first off, we're, oops.
00:32
Going to have an input we're going to have a user input three values so in particular then because this is we're going to use some sort of input function we're going to use the input function and we're going to just have the user input you know three values using input the input function and then with those three values we're going to determine determine the discriminant.
01:05
So of course, the discriminant, the three values, a, b, and c, of course, refer to the equation.
01:18
So if you have a quadratic equation, you have a, x squared, plus b, x, plus c, and we want to solve, of course, when this is equal to zero.
01:33
We want to find the x.
01:36
So in particular then the discriminant is the equation is the b squared minus 4a c.
01:50
And this is the discriminant.
01:54
So we'll call this the dis.
01:59
The dis, the discriminant is equal to this.
02:04
Particular then there's three cases we could possibly have.
02:09
We could have that the discriminant is less than zero and if it's less than zero we're going to return no real roots and then if it's if it's equal to zero then we have one real root and of course that root is equal to r is equal to negative b over 2a and if it's if it's greater than zero then we have two roots and we'll return these and this of course will be be our one equals to negative b over 2a plus the the the the the this discriminant to the half power or the square root of discriminant divided by 2a.
03:20
And we have r2, which is the negative of that, or what's sometimes called the conjugate, i guess.
03:31
And so we're going to write a program today that's going to do all of this.
03:37
So let's jump into the console and begin.
03:44
Okay, so here we are, and that's, i've described sort of the outline for what we're going to do.
03:51
Now we're going to go about making that happen.
03:55
So the first thing we want to do is we want the input.
03:58
So we're going to get the values a, b, and c, and this is going to be done using the trick that the author does quite often, which is something like this.
04:14
Please give three numbers separated by comma, by comma, or the coefficients.
04:33
Oeci, efficiency.
04:37
That's not how you spell coefficients, but not necessarily important here.
04:42
Coefficiency, actually, of the polynomial, of the, polynomial of the quadratic quadratic okay and what i want to do let me see sorry and i'm going to give it a tab just to give it a little spacing here you'll see what i mean okay now next what we're going to do is i'm going to actually call i'm going to say this is equal to and we have have b times b minus four times a times c okay so i'm just the turn oops not plus not equals to sorry minus typo there thank you for pointing it out charlie okay so now we have this um now we have to go through these uh cases so um now notice first off that these are, of course, four distinct cases.
05:53
The discriminant cannot, or three distinct cases, the discriminant cannot be greater than zero and equal zero at the same time.
06:02
But it's still probably good practice to get into as writing this as a, as using an if, and if, um, elf and else.
06:16
So we'll do it like that.
06:17
And what i mean is i'm going to first say, if the dis is equal to zero.
06:25
So what am i going to do? then i'm going to print the equation has no roots.
06:38
The equation has no real roots.
06:48
Okay.
06:52
And now i want to say l if this, thanks for pointing that out, charlie.
07:03
Yeah, you're right.
07:05
It should be less than zero, not equal zero.
07:09
I'm sorry.
07:10
Some of you are very, very observant...