← All topics
Quiz: Exceptions and Files: questions with answers
15 questions, each with the answer and a short explanation.
Take the timed quiz + get a certificate →- Q1. Which block ALWAYS runs, error or not?
- Q2. What error does int("12a") raise?
- Q3. What does opening an existing file with mode "w" do?
- Q4. What does this print? (code)
- Q5. Why use with open(...) as f:?
- Q6. What does this print? (code)
- Q7. What does this print? (code)
- Q8. What does this print? (code)
- Q9. Which mode adds to the end of an existing file?
- Q10. What does raise ValueError("bad age") do?
- Q11. What does this print? (code)
- Q12. What does this print? (code)
- Q13. Why is a bare except: (with no exception type) a bad idea?
- Q14. When reading a file line by line, why do we often call line.strip()?
- Q15. What does json.load(f) give you for a file containing {"name": "Asha", "cgpa": 8.7}?