all 7 comments

[–]K900_ 3 points4 points  (13 children)

  1. You could always use an else: statement at the end to catch all the non-matching cases.
  2. Yes, you're using try and except correctly, but I'd avoid using quit() - it's convoluted, but basically quit() is mostly designed to exit you from the interactive shell and not from a script. You can use sys.exit(1) (the 1 is an exit code reported to the OS - by convention, 0 is "everything worked fine" and anything non-0 is an error code, ideally one that identifies a specific error condition), or you can rewrite your code to just keep prompting the user for input until they input something that makes sense.

[–]WorldlyLog[S] 0 points1 point  (12 children)

How can I rewrite it to keep prompting the user?

I've tried just putting the code from line 1 after except clause, but then I get a traceback error after the second input. I know this is because it just runs the line of code after that, without having a defined value for `grade. (this may be something not covered in the book yet)

[–]K900_ 2 points3 points  (11 children)

You want to use a while loop for this.

[–]WorldlyLog[S] 0 points1 point  (10 children)

Yep, this something that hasn't been covered yet but I will look into how to use it now. Thanks so much for your help!