Starting from:

$24.99

CSE101 Lab 3 – Errors and Exceptions Exceptions Solution




• Why would you ever expect errors?
• If you can expect something, can’t you prevent that?

Exceptions

try:
<Your statements here> except <Name of first exception you wish to handle>:
<Your emergency code here> except <Name of first exception you wish to handle>:
<Your other emergency code here> else:
<If no exception…>
Exercise

You are expected to finish this task in less
than 60min
Closely examine the skeleton code (lab3.py) to infer the data types
• You are not allowed to change existing codes
• Only fill in the ‘TODO’ parts
Exercise

Task 1 Use exception handling to take care of the number format
• These dates should strictly consist of numbers
• Forcibly converting a non-numeric string to a number will result in an exception
Task 2 Use string methods to achieve the same result
• How do you find out if the string consists of numbers?
• You can find the appropriate method in the class slides or in the python documentation

More products