Velocity Reviews > newbie EOL while scanning string literal

# newbie EOL while scanning string literal

willlewis965@gmail.com
Guest
Posts: n/a

 06-25-2013
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)

willlewis965@gmail.com
Guest
Posts: n/a

 06-25-2013
FORGET ABOUT is_triangle(5,4,3) I POST IT AND DONT KNOW HOW TO EDIT MY QUESTION

Andrew Berg
Guest
Posts: n/a

 06-25-2013
On 2013.06.25 17:19, http://www.velocityreviews.com/forums/(E-Mail Removed) 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

rurpy@yahoo.com
Guest
Posts: n/a

 06-25-2013
On Tuesday, June 25, 2013 4:19:43 PM UTC-6, (E-Mail Removed) 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.

rurpy@yahoo.com
Guest
Posts: n/a

 06-25-2013
On 06/25/2013 04:19 PM, (E-Mail Removed) 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.

willlewis965@gmail.com
Guest
Posts: n/a

 06-26-2013
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.

rusi
Guest
Posts: n/a

 06-26-2013
On Wednesday, June 26, 2013 5:35:50 AM UTC+5:30, (E-Mail Removed) 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

Steven D'Aprano
Guest
Posts: n/a

 06-26-2013
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