## Making a program to solve a quadratic equation

This is the place for queries that don't fit in any of the other categories.

### Making a program to solve a quadratic equation

So here is my dilemma... I have been trying to write the code to solve a quadratic equation by entering a, b, and c yet I get an invalid syntax error could someone help?

Code: Select all
`from math import *def quadraticRoots( a , b , c ):    print( ax ** 2 + bx + c )    d = b ** 2 - 4 * a * c    if d < 0:       print ( "This equation has no solution" )    elif d == 0:       x = ( -b + sqrt (b ** 2 - 4 * a * c )) / ( 2 * a )       print (" This equation has one solution: " , x)    else:       x1 = ( -b - sqrt ( d )) / ( 2 * a)       x2 = ( -b - sqrt ( d )) / ( 2 * a)       print ("This equation has two solutions:" x1, x2)`
Last edited by Mekire on Wed Sep 04, 2013 10:35 pm, edited 1 time in total.
Reason: First post lock. COde tags added.
edwunclerlll

Posts: 1
Joined: Wed Sep 04, 2013 7:23 pm

### Re: Making a program to solve a quadratic equation

Hello and welcome to the forum. Please make sure you read this thread carefully.

Your initial syntax error is due to forgetting a comma in your final print line. There are further issues after this. Please report back.

-Mek
New Users, Read This
• Use code tags when posting code.
• Include any errors with your post (in code tags).
• Describe your problem; not your chosen solution.
• Make examples the minimum length to demonstrate your issue.

Mekire

Posts: 1711
Joined: Thu Feb 07, 2013 11:33 pm
Location: Tucson, Arizona

### Re: Making a program to solve a quadratic equation

Just read the error message. It shows you at what position something is wrong.

Code: Select all
`\$ python op.py   File "op.py", line 14    print ("This equation has two solutions:" x1, x2)                                               ^SyntaxError: invalid syntax`

Last edited by Somelauw on Sat Sep 07, 2013 12:14 pm, edited 1 time in total.
Join the #python-forum IRC channel on irc.freenode.net!
Somelauw

Posts: 82
Joined: Tue Feb 12, 2013 8:30 pm

### Re: Making a program to solve a quadratic equation

you need one just before that after your quotes
el_manu

Posts: 87
Joined: Mon Aug 19, 2013 8:30 am