0

I keep getting a syntax error on the second else: in this code. I've tried counting spaces, double checking braces, etc. I can't figure out what's wrong. Am I missing something?

if cclass == "wizard" or cclass == "cleric":
    level = input("What is your level of {}?".format(character_class))
    if (int(level)>=1 and int(level)<=20):
        print ("Welcome {}, {} of level {}".format(name, character_class, level)
    else:
        input("That level is out of range. Press enter to exit.")
        sys.exit()
else:
    input("You do not appear to be a character class that uses a grimoire.")
    sys.exit()
3
  • 1
    You are missing a closing parens here. There are nice editors out there that might make your life easier in future by highlighting those (I admit that it is easy to overlook, so why not taking advantage of current editors) Commented Jul 20, 2014 at 0:52
  • @SebastianRaschka I've been using gEdit, but clearly I need something more helpful. Thanks! Commented Jul 20, 2014 at 0:53
  • 1
    Also you can make level = int(input(..snip..)) and then check like this: if (1 <= level <=20) Commented Jul 20, 2014 at 1:07

1 Answer 1

2

You are missing a closing parenthesis on the print() call:

print ("Welcome {}, {} of level {}".format(name, character_class, level)
#     ^                                   ^                            ^^?
#     |                                    \-------- closed ----------/ |
#      \-------------------------- remains open -----------------------/

Python cannot see where this statement ends now and throws a syntax error when it then finds an else statement instead.

Sign up to request clarification or add additional context in comments.

1 Comment

Cripes. I was going mad looking at that. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.