newbie EOL while scanning string literal

W

willlewis965

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)
 
W

willlewis965

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

Andrew Berg

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

rurpy

[...]
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.
 
R

rurpy

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() *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.
 
W

willlewis965

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

rusi

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top