COMP1010 EXAM NOTES, sodbileg (z5452921)
Basics:
•	Indentation: Refers to the spaces at the beginning of a line of code. Indicates a block of code. Must be 4 spaces!!!! Have to use the same number of spaces in the same block or an error will occur.
•	Variables: Created when a value is applied to it (e.g., y = 3).
•	Casting: Manually ensuring a variable matches the required data type (e.g., y = int(3), z = float(3)).
•	Global variables: Exist outside functions. Local variables inside functions with the same name remain local; the global version stays unchanged. Note: Use of globals is restricted in exams.
•	F strings: Format strings by combining strings and numbers (e.g., f'My name is Maddy, I am {age}').
•	Boolean values: bool() returns True or False. Most values are True unless empty or 0.
•	Loops: For: Repeats over a sequence (string, list, range). While: Repeats while a condition is True. Must eventually become False!
•	Lists: Ordered, duplicate-friendly collections in square brackets [ ]. New items go to the end.
Functions / Keywords / Statements
Thing	What it does	Example
print(…)	Prints output	print('Hello World!')
len(…)	Finds length	print(len('meow'))
.upper + .lower	Returns upper/lower case	a.upper()
if / elif / else	Evaluates conditions in order	if x > 5: print('Big')
Data Types
Thing	What it does	Example
str / int	Text / Whole numbers	'Hello' / 20
float	Decimal numbers	2.0
list	Ordered, changeable sequence	['cat', 'dog']
dict	Mapping: key-value pairs	{'name': 'Maddy'}
NoneType	Represents no value	None
Web Apps!!!!!
3 main parts: Front-end (HTML), Back-end (Python), and Data (JSON/Lists).
Flow: User inputs data (forms) -> Python processes info -> Output (web page).
HTML Elements
Thing	What it does	Example
<h1> to <h6>	Headings (h1 is largest)	<h1>Heading</h1>
<p>	Paragraph	<p>Text</p>
<a>	Link	<a href='...'>Link</a>
<img>	Image	<img src='...' alt='text'>
<ul> / <ol>	Unordered (bullets) / Ordered (numbers) lists	
<form>	Accepts user input	<form method='post'>
<input>	Input box (text, password, submit)	<input type='text'>
<select>	Dropdown menu	<select><option>...</select>
Basic CSS Stuff
Syntax: selector -> property -> value. Inline Style Rule: <h1 style='color:pink;'>
Thing	What it does	Example
color	Text color (American spelling!)	color: pink;
font-size	Text size	font-size: 20px;
margin	Space OUTSIDE element	margin: 20px;
padding	Space INSIDE element	padding: 10px;
border	Line around element	border: 1px solid;
JSON & Complex Logic (High-HD)
JSON: Method of storing structured data (lists/dicts).
Searching & Filtering
# Find one item by ID
target = next((x for x in data if x['id'] == 123), None)

# Filter all matches
matches = [x for x in data if x['price'] < 50]

# Generate New ID
new_id = max([x['id'] for x in data] + [0]) + 1
Heuristics (Usability Discussion)
•	Visibility of System Status: Does the user know what's happening? (e.g., Success messages).
•	Match between System & World: Uses words/icons users understand (e.g., Trash icon).
•	Consistency: Same layout/colors on all pages. Navigation doesn't move.
•	Error Prevention: Using selects instead of inputs to stop typos.
•	Satisfaction: Is the page pleasant to look at? (Visual cohesion).
jsonhelpers.py (Sim Mautner)
import json, os

def create_if_not_exist(filename, empty_data):
    if not os.path.exists(filename):
        write_json_file(filename, empty_data)

def write_json_file(filename, info_to_save):
    with open(filename, 'w') as f:
        json.dump(info_to_save, f)

def read_json_file(filename):
    with open(filename, 'r') as f:
        return json.load(f)
