newbie EOL while scanning string literal

Discussion in 'Python' started by willlewis965@gmail.com, Jun 25, 2013.

  1. Guest

    I'am starting to learn python reading a book and I have to do some exercises but I can't understand this one, when I run it it says EOL while scanning string literal and a red shadow next to a line of code.

    I'm trying to get input from user. I have 3 questions:

    - Whats does EOL mean and in what circumstances can I face it again and how to avoid it.

    - Is this code correct or just looks silly, I am a newbie in programming how can I write this code better OR is it just not right 'specify'.

    - in how many ways can I specify the input has to be an integer, do I have to specify one by one or can I do something to get all input converted to integers in one step.

    THANKS.

    I AM USING PYTHON 3.3.2

    def is_triangle(a,b,c):
    if a+b<=c :
    print('it is a triaNgle')
    else:
    print('no')

    is_triangle(5,4,3)


    na=('type first integer n\')##THE RED SHADOW APPEARS HERE##
    naa=input(na)
    int(naa)
    ne=('type second integer n\')
    nee=input(ne)
    int(nee)
    ni=('type third integer \n')
    nii=input(ni)
    int(nii)

    is_triangle(na,ne,ni)
     
    , Jun 25, 2013
    #1
    1. Advertising

  2. Guest

    FORGET ABOUT is_triangle(5,4,3) I POST IT AND DONT KNOW HOW TO EDIT MY QUESTION
     
    , Jun 25, 2013
    #2
    1. Advertising

  3. Andrew Berg Guest

    On 2013.06.25 17:19, wrote:
    > na=('type first integer n\')##THE RED SHADOW APPEARS HERE##

    Here you escape the closing single quote. \n is a line feed, not n\. Also, the parentheses are unnecessary, and it looks like you are a
    assigning a tuple instead of a string.
    Syntax errors are often the result of typos; IDEs can easily detect such problems and will highlight them for you to make them obvious.
    > int(naa)

    Strings are immutable; this returns an integer, but you don't assign it to anything.
    > is_triangle(na,ne,ni)

    And here, you pass the strings you assigned for the input prompt instead of the integers you wanted to get.

    BTW, if you have an error, it helps if you copy/paste the full traceback. Many times, the exact issue is laid out in the traceback, and the
    solution is obvious to those with experience.
    --
    CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
     
    Andrew Berg, Jun 25, 2013
    #3
  4. Guest

    On Tuesday, June 25, 2013 4:19:43 PM UTC-6, wrote:
    >[...]
    > na=('type first integer n\')##THE RED SHADOW APPEARS HERE##


    You want \n at the end of the string, not n\.
    A backslash character \ in front of the ' escapes the ' and
    causes it to to be considered as a character in the string
    rather than ending the string.
     
    , Jun 25, 2013
    #4
  5. Guest

    On 06/25/2013 04:19 PM, wrote:
    > I'am starting to learn python reading a book and I have to do some
    > exercises but I can't understand this one, when I run it it says EOL
    > while scanning string literal and a red shadow next to a line of
    > code.
    >
    > I'm trying to get input from user. I have 3 questions:
    >
    > - Whats does EOL mean and in what circumstances can I face it again
    > and how to avoid it.
    >
    > - Is this code correct or just looks silly, I am a newbie in
    > programming how can I write this code better OR is it just not right
    > 'specify'.


    You'll find some other errors in your code after you
    fix the string problem. I'll leave them for you to find
    since they're pretty obvious.

    But one I'll mention because it is easy to miss because
    it produces wrong results rather than an error.

    Try running your program with the input: 5, 5, 1 (which
    shouldn't be a triangle).

    > int(naa)


    int() *returns* the int value of naa, but doesn't change
    the value of naa which remains a string.

    > - in how many ways can I specify the input has to be an integer, do I
    > have to specify one by one or can I do something to get all input
    > converted to integers in one step.


    naa = int (input ('type first integer\n'))

    is still three steps but a little more concise.

    Other ways are to put one input() call inside a loop
    that runs three times, saving each input in an array.

    Or you could read one string containing three numbers
    in one input statement, then split them into separate
    numbers.

    These may require python stuff you haven't gotten to
    yet though.
     
    , Jun 26, 2013
    #5
  6. Guest

    thanks man you answered my questions very clear, btw do you know of a place where I can learn python I know some tutorials but are 2. something and I'm using 3.3 and I've been told they are different.
     
    , Jun 26, 2013
    #6
  7. rusi Guest

    On Wednesday, June 26, 2013 5:35:50 AM UTC+5:30, wrote:
    > thanks man you answered my questions very clear, btw do you know of a place where I can learn python I know some tutorials but are 2. something and I'm using 3.3 and I've been told they are different.


    If you are a noob, its important to learn the basics easily rather than worry over arcane differences. The one basic diff between 2.7 and 3 is that in 2.7 you write:
    print "hello\n"
    In 3
    print("hello\n")

    The other differences are more arcane and need not concern you to start with.
    Getting a tutorial that suits you is far more important.
    After a couple of weeks you can switch to 3 if needed.
    Of course the sum of what you will need to learn is more and you may think you are wasting some time.
    Remember:
    1. Learning is important; learning curve is more important
    2. 2 and 3 dont differ in more than 5 percent of the details
     
    rusi, Jun 26, 2013
    #7
  8. On Tue, 25 Jun 2013 17:05:50 -0700, willlewis965 wrote:

    > thanks man you answered my questions very clear, btw do you know of a
    > place where I can learn python I know some tutorials but are 2.
    > something and I'm using 3.3 and I've been told they are different.


    Try here:

    http://mail.python.org/mailman/listinfo/tutor


    --
    Steven
     
    Steven D'Aprano, Jun 26, 2013
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ajay
    Replies:
    0
    Views:
    547
  2. Ajay
    Replies:
    2
    Views:
    7,419
    Ajay Brar
    Aug 4, 2004
  3. excite
    Replies:
    0
    Views:
    840
    excite
    Nov 2, 2006
  4. Chris Torek
    Replies:
    0
    Views:
    748
    Chris Torek
    Oct 15, 2010
  5. Anonieko Ramos

    What's wrong with rpc-literal? Why use doc-literal?

    Anonieko Ramos, Sep 27, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    400
    Anonieko Ramos
    Sep 27, 2004
Loading...

Share This Page