newbie EOL while scanning string literal

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

  1. willlewis965

    willlewis965 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.



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


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

    willlewis965, Jun 25, 2013
    1. Advertisements

  2. willlewis965

    willlewis965 Guest

    willlewis965, Jun 25, 2013
    1. Advertisements

  3. willlewis965

    Andrew Berg Guest

    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.
    Strings are immutable; this returns an integer, but you don't assign it to anything.
    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.
    Andrew Berg, Jun 25, 2013
  4. willlewis965

    rurpy Guest

    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.
    rurpy, Jun 25, 2013
  5. willlewis965

    rurpy Guest

    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() *returns* the int value of naa, but doesn't change
    the value of naa which remains a string.
    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

    These may require python stuff you haven't gotten to
    yet though.
    rurpy, Jun 26, 2013
  6. willlewis965

    willlewis965 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.
    willlewis965, Jun 26, 2013
  7. willlewis965

    rusi Guest

    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

    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.
    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
  8. Try here:
    Steven D'Aprano, Jun 26, 2013
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.