Search code examples
pythonpython-3.xsyntax-erroreol

Textbook is showing a double quote by itself but when I try it gives a SyntaxError


This book has twice now shown me " used by itself.

def chooseCave():
    cave = "
    while cave != '1' and cave != '2':
        print('Which cave will you go into?(Enter 1 or 2)')
        cave = input()

I get a SyntaxError: EOL while scanning string literal I'm unsure what to use in place of the single " to achieve what I would like.


Solution

  • I think you've misread the book slightly.

    You'll notice that they have used single quotes throughout the rest of the example to mark strings. I suspect that the first usage of this is no different.

    The example is actually;

    def chooseCave():
        cave = ''
        while cave != '1' and cave != '2':
            print('Which cave will you go into?(Enter 1 or 2)')
            cave = input()