Print is an Invalid Syntax? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

Print is an Invalid Syntax?

I keep getting an error for print being an invalid syntax and I am unsure what is wrong. Anyone know what I am doing wrong? Here is the program code: elif user_input == "quadform": num1 = float(input("Enter A value: ")) num2 = float(input("Enter B value: ")) num3 = float(input("Enter C value: ")) result = str(-num2 + sqrt(pow(num2, 2) - 4 * num1 * num3)/(num1 * 2) print("The answer is: " + result)

30th Nov 2018, 1:54 AM
Code Babylon
Code Babylon - avatar
15 Respuestas
+ 1
I entered prgms quadform 1 -2 -15 quit And it worked fine! Gave me 5, which is one of the two correct answers. What did you try?
30th Nov 2018, 4:24 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 1
Yes 😂 That's where we're supposed to enter all the inputs, in separate lines, like I showed in my examples.
30th Nov 2018, 4:29 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
Starting a code with "elif" would certainly throw a syntax error. If this is not your full code, please save it in Code Playground and share a link here. Thanks.
30th Nov 2018, 3:02 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
Here's the full code Kishalaya Saha https://code.sololearn.com/cWDOeEN07DQ8/?ref=app
30th Nov 2018, 3:05 AM
Code Babylon
Code Babylon - avatar
0
Oh, you have missmatched parentheses in line 61. It should be str(-num2 + sqrt(pow(num2, 2) - 4 * num1 * num3)/(num1 * 2))
30th Nov 2018, 3:23 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
Thank you! However, now I have an error on line 9.
30th Nov 2018, 3:27 AM
Code Babylon
Code Babylon - avatar
0
Oh, that's probably because Sololearn's Python doesn't support dynamic input-output interaction. All non-web codes here take all the inputs at the beginning and only *then* run it in their server and show us the output. But on a real interpreter the code should work fine. Here, I tested it with the following input (all entered together), and the code didn't give me any error: add 2 3 subtract 2 3 multiply 2 3 divide 2 3 quit Does that make sense? Please let me know :)
30th Nov 2018, 3:38 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
Everything but sqrt and quadform in prgms works fine. I can't do import math because that causes an error. I'm using Python's IDLE shell to test all of this. Also, thank you so much for your help so far. I really appreciate it.
30th Nov 2018, 3:41 AM
Code Babylon
Code Babylon - avatar
0
For sqrt, you just forgot to use str() on the result. Should be str(num**0.5). For quadform, we can do it by importing the math module, but it isn't necessary. Try this: str((-num2 + (num2**2 - 4*num1*num3)**0.5)/(2*num1)) I used the parentheses the correct way, and replaced the pow and the sqrt functions by just **2 and **0.5. In Python, those are more convenient 😉 Of course, this would only give you only one of the roots of the quadratic equation.
30th Nov 2018, 3:53 AM
Kishalaya Saha
Kishalaya Saha - avatar
0
The sqrt function works now, but quadform still doesn't work. The second parentheses at the very end is an invalid syntax, but without it, there is a type error
30th Nov 2018, 4:03 AM
Code Babylon
Code Babylon - avatar
0
Could you kindly update the code with what I suggested so I can see? I tried, and didn't get a syntax error.
30th Nov 2018, 4:08 AM
Kishalaya Saha
Kishalaya Saha - avatar
30th Nov 2018, 4:13 AM
Code Babylon
Code Babylon - avatar
0
Does a box pop up that says, "Seems like your program requires input"?
30th Nov 2018, 4:25 AM
Code Babylon
Code Babylon - avatar
0
Ok, now it's working. Thank you so much, Kishalaya!
30th Nov 2018, 4:33 AM
Code Babylon
Code Babylon - avatar
0
Happy to help! Have fun coding 😊
30th Nov 2018, 4:33 AM
Kishalaya Saha
Kishalaya Saha - avatar