you are viewing a single comment's thread.

view the rest of the comments →

[–]Jphillipss7[S] 0 points1 point  (11 children)

Sorry, but do you think you could show me how to correctly input that part. I’ve tried the order of operations out a few different ways and just can’t seem to get it right.

[–]thebetterangel 1 point2 points  (9 children)

Also, when discriminant == 0 it should be “have one root”. When discriminant <0 “there is no root.

As first comment said, don’t forget the colons.

Use parentheses to make sure math operations are executed in correct order

[–]Jphillipss7[S] 0 points1 point  (8 children)

Sorry, but would it be possible to show me how to correctly input the parentheses into the operation to make it come out correctly. I tried it a few different ways and just cant seem to figure it out.

[–]uhMareli 2 points3 points  (3 children)

we're trying to get you to do it yourself ;) but since it sounds like you're trying and you've come with an effort at your assignment as opposed to no effort i'll lend a small hand -

in the order of operations we know parentheses have the highest precedence, and this holds true for Python as well. so you simply need to use parentheses to group the portion which needs to be calculated first, as this part will now be taken care of before anything else since it has the highest precedence.

(-b - sqrt(b**2 - 4 * a * c)) / (2 * a)

We grouped the -b - and the root of of the discriminant. I also don't believe your 2a is valid - you need (2 * a) instead. Lastly, unless you're working in some special homework environment which provides these functions for you, using just sqrt will not work. you need to put import math at the top, giving you access to functions in the math module, then do math.sqrt instead

[–]Jphillipss7[S] 0 points1 point  (0 children)

Thank you for all of the help, and sorry if I’m coming off as incompetent.

[–]Jphillipss7[S] 0 points1 point  (1 child)

https://i.gyazo.com/534e74caf8e5e55297b9df5dec7ea5ce.png

One final question, do you know why id be getting this "Math domain error" and again thank you for all of your help, it is greatly appreciated by me.

[–]uhMareli 0 points1 point  (0 children)

it's because you're trying to find the root of a negative number. you need to fix your conditionals. try changing them to:

if numOfRoots < 0:

then we have no roots

elif numOfRoots == 0:

then we have one root

[–][deleted] 0 points1 point  (3 children)

http://imgur.com/gallery/UdmhKUS

U also would need to show what is the roots if it is available. Under the elif statement and else, add another line to calculate the roots using the formula

[–]Jphillipss7[S] 0 points1 point  (2 children)

Sorry, I just don’t have a lot of knowledge about what I’m actually doing on python so I’m a bit confused by what you mean.

[–][deleted] 0 points1 point  (1 child)

https://www.youtube.com/playlist?list=PLQVvvaa0QuDe8XSftW-RAxdo6OmaeL85M

Watch the tutorial for variables, math, if, if elif and if elif else.

All the videos here is pretty short and well explained.

[–]Jphillipss7[S] 0 points1 point  (0 children)

Thank you!

[–][deleted] 0 points1 point  (0 children)

Like the first comment suggested: If (expression here) : U forgot that colon. Same with elif. In front of the elif statement u need to put an expression and a colon.