Programming
π PROGRAMMING 511 EXAM CUE CARDS π
π Cue Card 1: File Handling
Front:
π What are the 4 file modes?
Back:
β r = Read file
β w = Write (creates/overwrites)
β a = Append (adds to file)
β open() = Opens file
Example:
Python
file = open("data.txt", "r")
content = file.read()
file.close()
π‘ Always remember to close files!
π Cue Card 2: If Statements
Front:
π€ When do we use an if statement?
Back:
Used when a condition must be checked.
Python
age = 18
if age >= 18:
print("Adult")
Relational Operators:
Operator
Meaning
==
Equal to
!=
Not equal to
>
Greater than
<
Less than
>=
Greater than or equal
<=
Less than or equal
π Cue Card 3: Logical Operators
Front:
π§ What are logical operators?
Back:
Used to combine conditions.
Python
and
or
not
Examples:
Python
if age >= 18 and age <= 60:
β Both conditions must be true.
Python
if mark >= 50 or bonus == True:
β At least one condition must be true.
π Cue Card 4: Nested Decisions
Front:
π³ What is a nested if?
Back:
An if inside another if.
Python
if salary >= 30000:
if years >= 2:
print("Approved")
π‘ Used when multiple conditions must be checked.
π Cue Card 5: Functions
Front:
β What are the 3 function parts?
Back:
1β£ Function Definition
Python
def greet():
2β£ Parameters
Python
def greet(name):
3β£ Function Call
Python
greet("Natasha")
4β£ Return Value
Python
def add(a,b):
return a+b
π Cue Card 6: While Loops
Front:
π What is a while loop?
Back:
Repeats while condition is True.
Python
count = 1
while count <= 5:
print(count)
count += 1
π‘ Be careful of infinite loops!
π Cue Card 7: Sentinel Values
Front:
πͺ What is a sentinel value?
Back:
A special value that stops a loop.
Python
name = ""
while name != "quit":
name = input("Enter name:")
Here: β Sentinel Value = "quit"
π Cue Card 8: Nested Loops
Front:
π What is a nested loop?
Back:
A loop inside another loop.
Python
for row in range(3):
for col in range(3):
print("*", end="")
Output:
***
***
***
β Commonly used for pattern questions.
π Cue Card 9: Input Validation
Front:
β What is input validation?
Back:
Ensures correct user input.
Python
age = input("Age: ").strip()
while not age.isdigit():
age = input("Enter valid age: ")
Important Functions:
β int()
β float()
β lower()
β strip()
π Cue Card 10: Debugging
Front:
π What errors can appear?
Back:
Syntax Error
Code written incorrectly.
Python
if age > 18
Missing :
Logic Error
Program runs but answer is wrong.
Python
total = price - vat
Should have been:
Python
total = price + vat
π Cue Card 11: Business Calculations
Front:
π° What business calculations may appear?
Back:
VAT
Python
vat = amount * 0.15
Discount
Python
discount = price * 0.10
Penalty
Python
penalty = balance * 0.05
Always:
Input
Process
Output
π Cue Card 12: IPO Principle
Front:
π What is IPO?
Back:
I β Input
User enters data
Python
name = input()
P β Processing
Calculations
Python
total = price * qty
O β Output
Python
print(total)
π‘ Every program follows IPO.
π Cue Card 13: Reading Requirements
Front:
π How do I answer programming questions?
Back:
Ask yourself:
β What inputs are needed?
β What calculations are needed?
β What decisions are needed?
β What output is required?
Then write:
INPUT β PROCESS β OUTPUT
π Cue Card 14: Complete Program Checklist
Front:
β Before submitting, check:
Back:
β Inputs collected correctly
β Variables named properly
β Functions used
β Decisions used correctly
β Loops end correctly
β Output displays correctly
β File opened and closed
β No syntax errors
β Tested with different values