Section B Pattern Bank
Refining procedural logic. Master standard searching, robust validation, and complex data handling.
Ticket Price Function (4 Marks)
Write a function calc_price(tickets) that checks:
- If tickets > 5, price is tickets * 50.
- Else, price is tickets * 60.
Return the calculated price.
Find the Max (4 Marks)
Take two numbers as input. Print the largest one. If equal, print "Equal".
Validation Loop (5 Marks)
Keep asking for an age while it is < 0 or > 100. Print "Accepted" once valid.
Running Total (5 Marks)
Loop 5 times. Ask for a number each time and add it to `total`. Print `total` at end.
Linear Search (4 Marks)
Loop through the fish list. If you find "Nemo", print "Found it!".
Entry Logic (4 Marks)
To enter, must be 15+ AND have a ticket ("yes"). Output "Enter" or "Stop".
Grading Function (4 Marks)
Function `get_grade(score)`. Score >= 50 returns "Pass", else "Fail".
Find Minimum (4 Marks)
Find and print the smallest number in the list `nums`.
Input Loop (5 Marks)
Ask for a password. Keep asking WHILE shorter than 5 characters. Print "Saved".
Selective Sum (5 Marks)
Sum only the ODD numbers (result 9) from the list `nums`.
Find the Winner (4 Marks)
Loop through `codes`. If you find "Golden", print "Winner".
Complex Logic (4 Marks)
If `age > 18` AND `paid == "Yes"` print "Welcome". Else "Sorry".
Counting Items
Count how many times "A" appears in the list.
Calculate Average
Print the average of the list numbers.
Clean String
Remove all spaces using `.replace()`.
Reverse List
Print the list in reverse order.
Password Check
If `p1` matches `p2`, print "Match".
Range Validation
If `age` is between 13 and 19 inclusive, print "Teen".
Find Max Position
Print index of the largest number.
Filter Positives
Append only positive numbers to `clean`.
Infinite Loop Break
Stop loop when `x` is 5 using `break`.
Skip Iteration
Skip printing the number 2 using `continue`.
Search Flag
Set `found` to True and break when "Key" is found.
Discount Logic
If `price` > 100, reduce it by 10%.
Complexity Mastered!
You have conquered standard algorithms. The final tier awaits.
Final Boss: Level 3