Welcome to your ICS 32 Final Prep
Visual, Interactive, and Comprehensive Review.
Lab Quizzes
Test your knowledge on Networking, Web APIs, and File Systems with interactive quizzes.
Lecture Review
Visual review of Lectures 9-17. Explore slides, diagrams, and key concepts.
Reference
Quick access to definitions, syntax, and key concepts covered in class.
Sample Final
Simulate the final exam experience with a timer and sample questions.
Select Quiz
Categories
Python Basics
Main Block
Ensures code only runs when executed directly, not when imported.
def main():
print("Running")
if __name__ == "__main__":
main()
python script.py → Prints "Running"
import script → Nothing prints
Exception Handling
Gracefully handle errors.
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero")
except Exception as e:
print(f"An error occurred: {e}")
finally:
print("Always runs")
Networking & Sockets
Client-Server Communication
Server Code
with socket.socket() as srv:
srv.bind(('localhost', 8000))
srv.listen()
conn, addr = srv.accept()
# ... handle connection
Client Code
with socket.socket() as client:
client.connect(('localhost', 8000))
client.sendall(b'Hello')
# ... receive response
Web APIs & JSON
JSON Data Structure
APIs typically return data in JSON format, which maps directly to Python dictionaries and lists.
{
"status": "success",
"data": {
"id": 101,
"name": "Product A",
"tags": ["new", "sale"]
}
}
import json
# ... fetch data ...
data = json.loads(response_text)
print(data['status']) # "success"
print(data['data']['name']) # "Product A"
print(data['data']['tags'][0]) # "new"
URL Encoding
import urllib.parse
params = {'search': 'hello world & more'}
query = urllib.parse.urlencode(params)
# Spaces -> + or %20
# Special chars (&, ?, =) -> %XX
Graphics & Animation
Coordinate System
width=48, height=48
canvas.create_rectangle(128, 80, 176, 128, color='blue')
# (x1, y1, x2, y2) -> Top-Left, Bottom-Right
Collision Detection (Bounding Box)
Box 1: (x1, y1, x2, y2)
Box 2: (a1, b1, a2, b2)
overlap =
(x2 > a1) and (x1 < a2) and
(y2 > b1) and (y1 < b2)
Data Science (Pandas)
DataFrame Visualization
| Index | Name | Age | City |
|---|---|---|---|
| 0 | Alice | 25 | New York |
| 1 | Bob | 30 | Los Angeles |
| 2 | Charlie | 35 | Chicago |
Select Column
df['Name']
# Returns: Alice, Bob, Charlie
Filter Rows
df[df['Age'] > 28]
# Returns: Bob, Charlie
Testing
Test Lifecycle
class TestMath(unittest.TestCase):
def setUp(self):
self.val = 10 # Runs before EVERY test
def test_add(self):
self.assertEqual(self.val + 5, 15)
def tearDown(self):
pass # Runs after EVERY test
ICS 32 Final Exam (Sample)
Ver A - 120 Minutes
Exam Structure
- Networks / Sockets / Protocols / Lab 7 / Project 2
- Web / URLs / Web APIs / Lab 8 / Project 2
- 2D Lists / Images / Lab 9 / Project 3
- Animation / Lab 10
- Test Driven Development / unit tests
- Data Visualization / Basic ML / Lab 11 / Project 4
Sample Questions
1. Conceptual
What is an IP address? Give an example.
Example:
192.168.1.1 (IPv4) or 2001:db8::1 (IPv6).
2. Code Comprehension
Given the provided server code, what happens when the code is executed?
- It creates a TCP socket and binds it to the specified host and port.
- It listens for incoming connections.
- When a client connects, it accepts the connection.
- It enters a loop:
- Reads data from the client.
- Prints the received data.
- Sends the same data back to the client.
- The loop terminates when the client disconnects (sends empty data).
3. Coding
Write a client program by implementing the start_client function. The client will first connect, then prompt user, then send data.
def start_client(server_address, server_port):
with socket.socket() as client:
client.connect((server_address, server_port))
send = client.makefile("w")
recv = client.makefile("r")
print(f"client connected to {server_address} on {server_port}")
while True:
msg = input("Enter message to send: ")
send.write(msg + "\r\n")
send.flush()
srv_msg = recv.readline().strip()
print("Response: ", srv_msg)