LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-30-2013, 08:05 PM   #1
antonia_alessandra
LQ Newbie
 
Registered: Mar 2013
Posts: 2

Rep: Reputation: Disabled
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.
 
Old 03-31-2013, 01:17 AM   #2
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 222

Rep: Reputation: 62
Quote:
Originally Posted by antonia_alessandra View Post
if x = 1
^
SyntaxError: invalid syntax
Try using this code:

if x == 1:
 
1 members found this post helpful.
Old 03-31-2013, 02:38 AM   #3
antonia_alessandra
LQ Newbie
 
Registered: Mar 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
That worked! Thank you!
Any idea why I had to write it that way?
 
Old 03-31-2013, 02:49 AM   #4
rosehosting.com
Member
 
Registered: Jun 2012
Location: Missouri, USA
Posts: 222

Rep: Reputation: 62
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.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Error with LDAP on CentOS. ldapadd returns: Invalid DN syntax (34) Abakus Linux - Server 2 08-22-2012 05:03 AM
ldap_add:Invalid Syntax Error (23) donanap Linux - General 3 09-07-2011 09:33 AM
[SOLVED] Python Installed; bash command: python base.py. gets syntax error in base.py cre84j Linux - Software 4 01-23-2011 04:46 PM
[python] syntax Error : invalid syntax Python_user Programming 2 09-06-2009 12:52 PM
[Python] Invalid Syntax - If statement LinuxCrayon Programming 4 12-07-2007 09:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration