Path: csiph.com!usenet.pasdenom.info!gegeweb.org!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; '"this': 0.03; 'causing': 0.04; 'syntax': 0.04; 'error:': 0.07; 'great.': 0.07; 'smallest': 0.07; 'here?': 0.09; 'input,': 0.09; 'main()': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'assume': 0.14; 'wrote': 0.14; 'c):': 0.16; 'colon.': 0.16; 'eliminating': 0.16; 'eof': 0.16; 'finds': 0.16; 'main():': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'renamed': 0.16; 'risks,': 0.16; 'script,': 0.16; 'subject:import': 0.16; 'syntaxerror:': 0.16; 'unexpected': 0.16; 'unsafe': 0.16; 'library': 0.18; 'version.': 0.19; 'thanks.': 0.20; 'seems': 0.21; 'input': 0.22; 'import': 0.22; 'print': 0.22; 'error': 0.23; 'specify': 0.24; 'math': 0.24; 'skip:" 40': 0.26; 'header:X-Complaints-To:1': 0.27; 'idea': 0.28; 'function': 0.29; 'forgot': 0.30; '"",': 0.31; 'correctly.': 0.31; 'occurs': 0.31; "user's": 0.31; 'anyone': 0.31; 'file': 0.32; 'run': 0.32; '(most': 0.33; '"the': 0.34; 'problem.': 0.35; 'but': 0.35; 'version': 0.36; 'library.': 0.36; "i'll": 0.36; 'should': 0.36; 'error.': 0.37; 'wrong': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'first': 0.61; 'real': 0.63; 'skip:n 10': 0.64; 'here': 0.66; '11.': 0.74; 'subject::': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re:import math error Date: Sun, 16 Nov 2014 17:55:35 -0500 (EST) Organization: news.gmane.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 97.73.240.77 X-Newsreader: PiaoHong.Usenet.Client.VIP:1.65 X-Archive: encrypt X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416178533 news.xs4all.nl 2954 [2001:888:2000:d::a6]:42763 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80927 You forgot to specify your Python version here. ryguy7272 Wrote in message: > When I type 'import math', it seems like my Python recognizes this library. Great. When I try to run the following script, I get an error, which suggests (to me) the math library is not working correctly. Nothing to do with the math library. It's a syntax error. And it occurs before the first call into the math library. > > Script: > import math > def main(): > print "This program finds the real solutions to a quadratic" > print > a, b, c = input("Please enter the coefficients (a, b, c): ") Ouch. input is unsafe, anot recommended. That's why python 3 renamed the raw_input function to input, eliminating the unsafe version. Nevertheless, I'll assume you understand the risks, and we'll go on with your problem. > discRoot = math.sqrt(b * b - 4 * a * c) > root1 = (-b + discRoot) / (2 * a) > root2 = (-b - discRoot) / (2 * a) > print > print "The solutions are:", root1, root2 > main() > > Error: > Traceback (most recent call last): > File "C:\Users\Ryan\Desktop\QuadraticEquation.py", line 11, in > main() > File "C:\Users\Ryan\Desktop\QuadraticEquation.py", line 5, in main > a, b, c = input("Please enter the coefficients (a, b, c): ") > File "", line 1 > (1,1,2): > ^ > SyntaxError: unexpected EOF while parsing The error is occurring while parsing the user's input, which should not have a colon. The smallest flaw with using input () is that user error cause strange looking exceptions. > > The last line is line 11. It seems like I need this, but that's what's causing the error. Does anyone here have any idea what is wrong here? > > Thanks. > -- DaveA