how to avoid EOL in python

Asked

Viewed 145 times

-4

I have this code:

número = 4
chute = input('quanto é 2+2?:\')

if chute == número:
    print('parabéns, vc acertou :)')
else:
    print('ops, parece que você errou, tente novamente que você vai conseguir acertar. Você consegue :)')

And this keeps popping up:

Syntaxerror: EOL while Scanning string literal

How to correct?

2 answers

2

The error is Porq vc is escaping the single quote character at the end of the function input

Try this: chute = input('quanto é 2+2?:')

In addition, python has features different from other languages such as indentation and the use of : at the end of the commands.

Another thing is you’ll be comparing a int with a str given what function input() returns.

Try this: chute = int(input('quanto é 2+2?:'))

Python does not complain about accent in variables, but is not the most appropriate.


número = 4
chute = int(input('quanto é 2+2?:'))

if chute == número:
    print('parabéns, vc acertou :)')
else:
    print('ops, parece que você errou, tente novamente que você vai conseguir acertar. Você consegue :)')

print

  • 1

    I did that right there, and you’re still making the mistake

  • 1

    I edited the answer with the changed code and a working print to see if it helps you!

  • 1

    Question, the int means oq? It’s q I’m learning using a workbook q I downloaded from the internet

  • 1

    int() is a function that converts the parameter passed to integer type. Ex: "4" is a string, by being in quotes, that with the int("4") flipped 4 which is a number

  • Maybe learning from someone teaching is better! I recommend the videos from Curso em Vídeo by Gustavo Guanabara

  • 1

    thanks for the tip, we’re together man is we :)

  • 1

    refit the code from scratch and now will give error: Unexpected ident

  • which IDE you are using? it usually points to the error line. This looks like you have misidentified some part of the code

  • 1

    to using IDE 3.9.2. Plus I was able to resolve the error more now n is showing the answer q I want

  • agr the problem should be in the comparison, no if

  • @Kingtrollex if I helped you, mark the answer as right please :D

  • I can’t seem to solve this problem

  • what the code looks like?

  • i am unable to progress with the error: Unexpected ident. I have written and rewritten the code several times and I am stuck in the same place

  • You have to give exact 4 spaces or press tab 1 time

  • thanks for the tip

  • I did what you said and the same mistake keeps happening.

Show 12 more comments

0

EOL while Scanning string literal

Occurs when any of the Quotes('', "", """""") is opened and not closed properly.

E.g

TEST THE EXAMPLES BELOW IN PYTHON PROMPT

IDLE ENVIRONMENT CONTAINING THREE ANGLE BRACKETS (>>>)

Testing the examples below will all result in errors EOL.

>>> 'Seu texto vai aqui
>>> 'Seu texto vai aqui"
>>> "Seu texto vai aqui"""

If single quotes have been opened, it should be closed. It is worth noting that quotation marks are different from each other.

'' -> single quotes

"" -> double quotes

"""""" -> triple quotes

If you open simply, only single quotes can close simple quotes. And so on.

And in your case, a "Character escape" was incorrectly used which is this backslash with the single quote (\'), making the Python interpreter understand that its single quote at the end is considered a literal quote, that is, part of the text, rather than a quote or a Python text delimiter. To resolve, add a single quote (\'') or remove the backslash (').

Browser other questions tagged

You are not signed in. Login or sign up in order to post.