0% found this document useful (0 votes)
2 views2 pages

Python Exam Prep: 30-Minute Guide

This document provides a 30-minute warm-up plan and essential topics to review for an Intro to Python exam, covering key concepts from weeks 1 to 7. It includes a list of common traps to avoid, templates for functions and data structures, and a final checklist for submission. The focus is on ensuring fluency in Python basics, including variables, loops, functions, OOP, and error handling.

Uploaded by

Knight Goose
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Exam Prep: 30-Minute Guide

This document provides a 30-minute warm-up plan and essential topics to review for an Intro to Python exam, covering key concepts from weeks 1 to 7. It includes a list of common traps to avoid, templates for functions and data structures, and a final checklist for submission. The focus is on ensuring fluency in Python basics, including variables, loops, functions, OOP, and error handling.

Uploaded by

Knight Goose
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Intro Python — Last 30 Minutes Mini-Sheet (Weeks 1–7)

Read once before the exam. Then do 2 micro-tests in a scratch cell. Focus: points-per-minute.

30-minute warm-up plan (do not overrun)


• 0–5 min: Skim this sheet (patterns + traps).
• 5–15 min: Part A warm-up: (a) trace 1 loop, (b) trace 1 [Link], (c) fix 1 tiny bug (=+ / index / wrong return).
• 15–25 min: From-scratch warm-up: write one template from memory (file→counts OR list filter OR dict count).
• 25–30 min: Style check: type hints + docstring + return variable + no debug prints.

Week-by-week: what you must be fluent in


• W1 Python intro: variables, types (int/float/str/bool), print, input (if used), basic operators.
• W2 Conditionals & loops: if/elif/else, for/while, range, break/continue, % (mod), // (floor division).
• W3 Functions & lists: def/return vs print, parameters, local scope, list methods (append/pop), mutation vs new list
(slicing/+).
• W4 Functions & dicts: dict creation, lookup, overwriting keys, .get(k,0)+1 counting, .items() iteration.
• W5 OOP: class, __init__, self, attributes, methods; how to construct and call methods.
• W6 Inheritance & reading data: super().__init__(...), extending classes; with open(...) as f, strip/lower/split, building list/dict
from lines.
• W7 Error-handling: try/except; common exceptions: ValueError (int()), IndexError, KeyError; return safe fallback.

Part A traps (memorize)


• Aliasing: b=a shares list; append/pop affects both. a=a+[x] and a=a[:] create a NEW list.
• enumerate(xs) → (i, x). zip(a,b) → pairs.
• Dict: same key overwritten; len(d) counts keys (including 'len' if you store it).
• Common typos: =+ vs +=, wrong index (xs[2] vs xs[1]), wrong return var, missing quotes on string keys, 'r' must be "r" in
open().
• append returns None; don’t do x = [Link](...).

Copy templates (adapt quickly)


Function skeleton (with types + docstring)
def f(x: TYPE) -> RET:
"""What it does/returns."""
result = ... # init correct type
return result

List filter / build


out: list[T] = []
for x in xs:
if CONDITION:
[Link](x_or_transform)
return out

Dict count (histogram)


counts: dict[str, int] = {}
for x in xs:
counts[x] = [Link](x, 0) + 1
return counts

File → words → counts


counts: dict[str, int] = {}
with open(path, "r") as f:
for line in f:
for w in [Link]().lower().split():
if w:
counts[w] = [Link](w, 0) + 1
return counts

Max with tie-break (no lambda)


winner = ""
best = -1
for name, count in [Link]():
if count > best or (count == best and (winner == "" or name < winner)):
best = count
winner = name

OOP + inheritance mini-pattern


class A:
def __init__(self, x: int):
self.x = x

class B(A):
def __init__(self, x: int, y: int):
super().__init__(x)
self.y = y

try/except safe int


try:
return int(s)
except ValueError:
return 0

Final submission checklist


• Function name/signature unchanged.
• Type hints present (params + return).
• Docstring present.
• Return the correct variable/type.
• No leftover debug prints (unless asked).
• Ran the provided tests once from top to bottom.

You might also like