LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Invalid Syntax Error on Python Function (https://www.linuxquestions.org/questions/linux-newbie-8/invalid-syntax-error-on-python-function-4175456215/)

antonia_alessandra 03-30-2013 08:05 PM

Invalid Syntax Error on Python Function
 
Hey guys,

I have been trying to write a function in python and keep getting an invalid syntax error and I'm not sure why. This is my current code:
Code:

def aero_top(x):
    y =(0.102/0.20)*((0.29690*sqrt(x))-(0.126*x)- 
    (0.35160*(x**2))+ (0.28430*(x**3))-
    (0.10150*(x**4))) 
    if x = 1.0
      y = 0.0
    x = x/5.
    y = y/5.
    return (x,y,0.0)

The error I keep getting is:
Code:

File "NACA_Aerofoil_Spyder.py", line 22
    if x = 1
        ^
SyntaxError: invalid syntax

Any ideas??
Thanks.

rosehosting.com 03-31-2013 01:17 AM

Quote:

Originally Posted by antonia_alessandra (Post 4921916)
if x = 1
^
SyntaxError: invalid syntax

Try using this code:

if x == 1:

antonia_alessandra 03-31-2013 02:38 AM

That worked! Thank you!
Any idea why I had to write it that way?

rosehosting.com 03-31-2013 02:49 AM

The Python language has many similarities to Perl, Java and C. However, there are some definite differences between the languages.
Many Python constructs, like if, while, and for, require a terminating colon : . Also, '=' is the assignment operator while '==' is the 'is equal to' comparison operator.


All times are GMT -5. The time now is 06:34 PM.