+ 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)
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?
+ 1
Yes 😂
That's where we're supposed to enter all the inputs, in separate lines, like I showed in my examples.
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.
0
Here's the full code Kishalaya Saha
https://code.sololearn.com/cWDOeEN07DQ8/?ref=app
0
Oh, you have missmatched parentheses in line 61. It should be
str(-num2 + sqrt(pow(num2, 2) - 4 * num1 * num3)/(num1 * 2))
0
Thank you! However, now I have an error on line 9.
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 :)
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.
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.
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
0
Could you kindly update the code with what I suggested so I can see? I tried, and didn't get a syntax error.
0
Does a box pop up that says, "Seems like your program requires input"?
0
Ok, now it's working. Thank you so much, Kishalaya!
0
Happy to help! Have fun coding 😊