Skills101
← All practice quizzes

Quiz: Exceptions and Files

5 questionsNo time limitPass: 60%+10 XP on first pass

Handle errors gracefully with try, except, else and finally, raise your own errors, and read and write text, CSV and JSON files safely with "with open()".

Log in to take the quiz

Free account · see your score, answers and explanations, earn XP

  1. Question 1

    Which block ALWAYS runs, error or not?

  2. Question 2

    What error does int("12a") raise?

  3. Question 3

    What does opening an existing file with mode "w" do?

  4. Question 4

    What does this print?

    try:
        x = [1, 2][5]
    except IndexError:
        print("bad index")
    else:
        print("ok")
    
  5. Question 5

    Why use with open(...) as f:?