Learning Target: I can recognize and fix syntax errors in Python code.
Syntax errors are like spelling and grammar mistakes in writing. They prevent the code from running.
print("Hello, World!"
Fix the syntax error in the code above and print a greeting message.
Try it here:
Learning Target: I can identify and correct logic errors in Python code.
Logic errors occur when the code runs but produces incorrect results.
score = 85
bonus = 10
total = score + bonus * 2
print(total) # Expected output: 190
Fix the logic error in the code above to get the expected output.
Try it here:
Learning Target: I can identify and fix runtime errors in Python code.
Runtime errors occur while the code is running and can cause the program to crash.
numbers = [1, 2, 3]
print(numbers[3]) # IndexError: list index out of range
Fix the runtime error in the code above to avoid the IndexError.
Try it here:
Learning Target: I can use try, except, else, and finally to handle exceptions in Python code.
Exception handling allows you to manage errors gracefully and keep the program running.
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero!")
else:
print("Division successful!")
finally:
print("Execution complete.")
Modify the code above to handle a different type of exception.
Try it here:
Learning Target: I can write unit tests using the unittest module in Python.
Unit testing helps ensure that individual units of code work as expected.
import unittest
def add(a, b):
return a + b
class TestAddFunction(unittest.TestCase):
def test_add(self):
self.assertEqual(add(2, 3), 5)
if __name__ == '__main__':
unittest.main()
Write a unit test for a function that subtracts two numbers.
Try it here: