Python Elif Syntax Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about elif not working in python Stack Overflow the company Business Learn more about hiring developers or posting ads else invalid syntax python 3 with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow python if statement not working is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up elif giving syntax error python? up vote 3 down vote favorite I'm trying else: ^ syntaxerror: invalid syntax to parse an XML document and get certain tags. I'd like to grab the name tag (only if it's the name tag nested within artist) and the title tag (only if it's the one nested within release). That's not too important, though, the important thing is that I'm for some reason getting an error saying the elif statement is invalid syntax I've looked through other posts and made sure that
Else Syntax Error Python
my tabbing is correct and that there aren't any extra newlines after any of the if's. This is the code snippet: from lxml import etree import sys #infile = raw_input("Please enter an XML file to parse: ") outfile = open('results.txt', 'a') path = [] for event, elem in etree.iterparse('releases7.xml', events=("start", "end")): if event == 'start': path.append(elem.tag) elif event == 'end': # process the tag if elem.tag == 'name': if 'artist' in path and not 'extraartists' in path and not 'track' in path: outfile.write( 'artist = ' + elem.text.encode('utf-8') + '\n' ) elif elem.tag == 'title': if 'release' in path and not 'track' in path: outfile.write( 'release title = ' + elem.text.encode('utf-8') + '\n') else: print 'nonrelease' path.pop() This is the error: File "DataDestroy_Fast.py", line 18 elif elem.tag == 'title': ^ SyntaxError: invalid syntax (Note: Using Python2.7 on Mac OSX) python python-2.7 share|improve this question edited May 25 '13 at 2:18 asked May 25 '13 at 2:03 arc 197313 outfile.write( 'artist = ' + elem.text.encode('utf-8') + '\n' ); << does it suppose to have an extra ; there? That jumps out to me... –George May 25 '13 at 2:05 oh, that was just put there because i wanted to see if it made
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about
Syntax Error Elif Bash
hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask indentation in python Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. unindent does not match any outer indentation level Join them; it only takes a minute: Sign up Syntax error if, elif statements [closed] up vote 0 down vote favorite I'm having trouble trying to get this code to work. It keeps coming up with SyntaxError: invalid syntax http://stackoverflow.com/questions/16745740/elif-giving-syntax-error-python adult = int(input("No adults:") child = int(input("No children:") type = int(input("Well done or Rare:") if adult < 0: print("Enter number >=0) elif child < 0: print("Enter number >=0) elif type != "W" or type != "R": print("error") If the user types in the correct number I want it to go to the next question in line. If user inputs incorrect data I want the error message and then the same question to be repeated. Thanks!! python eclipse syntax-error share|improve http://stackoverflow.com/questions/22587563/syntax-error-if-elif-statements this question edited Mar 23 '14 at 7:45 mok 3,95311241 asked Mar 23 '14 at 5:49 Meg 185 closed as off-topic by thefourtheye, Paul Hankin, devnull, Bibhas, Lorenz Meyer Mar 23 '14 at 6:57 This question appears to be off-topic. The users who voted to close gave this specific reason:"This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – thefourtheye, Paul Hankin, devnull, Bibhas, Lorenz MeyerIf this question can be reworded to fit the rules in the help center, please edit the question. You are missing a double quotes in print("Enter number >=0) –thefourtheye Mar 23 '14 at 5:50 add a comment| 2 Answers 2 active oldest votes up vote 1 down vote accepted Try this: adult = int(input("No adults:")) child = int(input("No children:")) type = int(input("Well done or Rare:")) if adult < 0: print("Enter number >=0") elif child < 0: print("Enter number >=0") elif type != "W" or type != "R": print("error") Compare it with your code. Your code includes: missing ), ", bad indentation. Note: Using type as a variable will mask the built-in function "type" within the scope of th
Get Kubuntu Get Xubuntu Get Lubuntu Get UbuntuStudio Get Mythbuntu Get Edubuntu Get Ubuntu-GNOME Get UbuntuKylin Ubuntu Code of Conduct Ubuntu Wiki Community https://ubuntuforums.org/showthread.php?t=1768377 Wiki Other Support Launchpad Answers Ubuntu IRC Support AskUbuntu Official Documentation User Documentation Social Media Facebook Twitter Useful Links Distrowatch Bugs: Ubuntu PPAs: Ubuntu Web Upd8: Ubuntu OMG! Ubuntu Ubuntu http://www.programmingforums.org/post219426.html Insights Planet Ubuntu Activity Page Please read before SSO login Advanced Search Forum The Ubuntu Forum Community Ubuntu Specialised Support Development & Programming Programming Talk Python if & elif syntax error problems Having an Issue With Posting ? Do you want to help us debug the posting issues ? < is the place to report it, thanks ! Results 1 to 6 of 6 Thread: Python if & elif problems Thread Tools Show Printable Version Subscribe to this Thread… Display Linear Mode Switch to Hybrid Mode Switch to Threaded Mode May python elif syntax 27th, 2011 #1 DarkSnake-Kobra View Profile View Forum Posts Private Message 5 Cups of Ubuntu Join Date May 2011 Beans 21 Python if & elif problems Hi everyone. I'm a beginner to Python and having some problems with the if and elif statements. I did some research and looks like I'm not alone when it comes to getting an invalid syntax error. I need some help getting it in the right format. Thanks! Code: >>> OJ_price = 2.50 >>> if OJ_price < 1.25: print("Get one, I'm thirsty.") >>> elif OJ_price <= 2.00: SyntaxError: invalid syntax >>> Adv Reply May 27th, 2011 #2 TwoEars View Profile View Forum Posts Private Message Gee! These Aren't Roasted! Join Date May 2010 Beans 171 Re: Python if & elif problems Originally Posted by DarkSnake-Kobra Hi everyone. I'm a beginner to Python and having some problems with the if and elif statements. I did some research and looks like I'm not alone when it comes to getting an invalid syntax error. I need some help getting it in the right format. Tha
Page... Thread Tools Display Modes Oct 10th, 2011, 12:56 PM #1 uperkurk Programmer Join Date: Nov 2005 Posts: 55 Rep Power: 11 elif and else not working? When I used C++ it was if and else, on the tutorials im following elif doesnt work... (Toggle Plain Text) >>> #This is a program about elif and else not working >>> a = 1 >>> b = 2 >>> if a < b: print("I'm less than b") elif print("I'm more than b") SyntaxError: invalid syntax >>> >>> #This is a program about elif and else not working >>> a = 1 >>> b = 2 >>> if a < b: print("I'm less than b") elif print("I'm more than b") SyntaxError: invalid syntax >>> uperkurk View Public Profile Find More Posts by uperkurk Oct 10th, 2011, 1:02 PM #2 King Professional Programmer Join Date: Jan 2006 Location: Ontario, Canada Posts: 771 Rep Power: 11 Re: elif and else not working? your elif has no condition... so just use and else. __________________ I am Addicted to Linux! King View Public Profile Find More Posts by King Oct 10th, 2011, 1:20 PM #3 uperkurk Programmer Join Date: Nov 2005 Posts: 55 Rep Power: 11 Re: elif and else not working? (Toggle Plain Text) >>> #This is a program about elif and else not working >>> a = 1 >>> b = 2 >>> if a < b: print("I'm less than b") else print("I'm more than b") SyntaxError: invalid syntax >>> >>> #This is a program about elif and else not working >>> a = 1 >>> b = 2 >>> if a < b: print("I'm less than b") else print("I'm more than b") SyntaxError: invalid syntax >>> like that? after all I only want it to print I'm more than b if the argument is true, which ofcourse it isnt. uperkurk View Public Profile Find More Posts by uperkurk Oct 10th, 2011, 3:28 PM #4 sixstringartist Programming Guru Join Date: Jun 2005 Posts: 1,333 Rep Power: 13 Re: elif and else not working? No offense but this is a waste of our time. This is a simple syntax issue that can easily be resolved by looking at the python documentation. You will never last as a programmer if you cannot search for yourself. http://docs.python.org/tutorial/controlflow.html sixstringartist View Pu