Level 2: Standard Algorithms

Core Patterns (4 - 6 Marks)

1. 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 price.

Examiner's Notes

  • 1 Mark: Defining function with correct parameter calc_price(tickets).
  • 1 Mark: Correct If statement logic (> 5).
  • 1 Mark: Correct calculation lines.
  • 1 Mark: Returning the value.

2. Find the Max (4 Marks)

Take two numbers as input. Print the largest one.
If they are equal, print "Equal".

Examiner's Notes

  • 1 Mark: Correctly casting inputs to integers.
  • 1 Mark: First condition (if n1 > n2).
  • 1 Mark: Handling equality with elif/else.
  • 1 Mark: Correct print statements.

3. Validation Loop (5 Marks)

Ask for an age. Keep asking WHILE the age is less than 0 or greater than 100.
Output "Accepted" when valid.

Examiner's Notes

  • 1 Mark: Correct While logic (OR operator for range bounds).
  • 1 Mark: Using int() for input.
  • 1 Mark: Updating loop variable inside loop (to prevent infinite loop).

4. Running Total (5 Marks)

Loop 5 times. Each time, ask for a number. Add it to total.
Print total at the end.

Examiner's Notes

  • 1 Mark: Correct loop range (5 iterations).
  • 1 Mark: Taking input inside loop.
  • 1 Mark: Accumulating total correctly (total = total + n).
  • 1 Mark: Printing outside the loop.

5. Linear Search (4 Marks)

Loop through the list. If you find "Nemo", print "Found it!".

Examiner's Notes

  • 1 Mark: Iterating through list items.
  • 1 Mark: Checking condition == "Nemo".
  • 1 Mark: Correct print message.

6. Entry Logic (4 Marks)

To enter, you must be 15 or older AND have a ticket.
Input age and has_ticket (input "yes" or "no").
Output "Enter" or "Stop".

Examiner's Notes

  • 1 Mark: Checking Age >= 15.
  • 1 Mark: Checking Ticket == "yes".
  • 1 Mark: Combining with AND logic.
  • 1 Mark: Correct Else branch.

7. Grading Function (4 Marks)

Write a function get_grade(score).
If score >= 50 return "Pass", else "Fail".

Examiner's Notes

  • 1 Mark: Function definition syntax.
  • 1 Mark: Correct comparison >= 50.
  • 1 Mark: Returning strings from function.

8. Find Minimum (4 Marks)

Given 3 numbers, print the smallest one.

Examiner's Notes

  • 1 Mark: Initializing minimum variable.
  • 1 Mark: Loop logic or comparison logic.
  • 1 Mark: Updating minimum if smaller found.

9. Input Loop (5 Marks)

Ask for a password. Keep asking WHILE it is shorter than 5 characters.
Print "Saved" when done.

Examiner's Notes

  • 1 Mark: Correct Loop condition (len(pw) < 5).
  • 1 Mark: Updating variable inside loop.
  • 1 Mark: Final print statement.

10. Selective Sum (5 Marks)

Sum only the ODD numbers (1, 3, 5) in the list.

Examiner's Notes

  • 1 Mark: Loop through logic.
  • 1 Mark: Using Modulo % to check for odd.
  • 1 Mark: Accumulating sum only if condition met.

11. Find the Winner (4 Marks)

Loop through codes. If you find "Golden", print "Winner".

Examiner's Notes

  • 1 Mark: Correct comparison string "Golden".
  • 1 Mark: Printing "Winner".
  • 1 Mark: Correct indentation.

12. Complex Logic (4 Marks)

If age > 18 AND paid == "Yes" print "Welcome". Else "Sorry".

Examiner's Notes

  • 1 Mark: Checking Age condition.
  • 1 Mark: Checking Paid condition.
  • 1 Mark: Using and operator.
  • 1 Mark: Correct indentation and Else block.

13. Counting Items (1 Mark)

Count how many times "A" appears in the list.

Examiner's Notes

  • 1 Mark: Using .count() method correctly.

14. Calculate Average (2 Marks)

Calculate and print the average of the numbers in the list.

Examiner's Notes

  • 1 Mark: Calculating sum.
  • 1 Mark: Dividing by length (len()).

15. Clean String (1 Mark)

Remove all spaces from the string using replace().

Examiner's Notes

  • 1 Mark: Correct use of replace(" ", "").

16. Reverse List (1 Mark)

Print the list in reverse order.

Examiner's Notes

  • 1 Mark: Using slicing [::-1] or .reverse().

17. Password Check (2 Marks)

Check if p1 matches p2. If yes, print "Match".

Examiner's Notes

  • 1 Mark: String comparison algorithm.
  • 1 Mark: Correct conditional print.

18. Range Validation (1 Mark)

Check if age is between 13 and 19 (inclusive). Print "Teen".

Examiner's Notes

  • 1 Mark: Correct compound condition checking.

19. Find Max Position (2 Marks)

Find and print the index of the largest number.

Examiner's Notes

  • 1 Mark: Finding the max value.
  • 1 Mark: Finding and printing its index.

20. Filter Positives (2 Marks)

Create a loop that appends only positive numbers to clean.

Examiner's Notes

  • 1 Mark: Looping through list.
  • 1 Mark: Checking condition and appending to new list.

21. Infinite Loop Break (1 Mark)

Stop the loop when x is 5 using break.

Examiner's Notes

  • 1 Mark: Correct use of break inside condition.

22. Skip Iteration (1 Mark)

Use continue to skip printing the number 2.

Examiner's Notes

  • 1 Mark: Correct use of continue.

23. Search Flag (2 Marks)

Loop through list. If "Key" is found, set found to True and break.

Examiner's Notes

  • 1 Mark: Setting flag to True on find.
  • 1 Mark: Breaking loop after find.

24. Discount Logic (1 Mark)

If price is over 100, reduce it by 10%. Print new price.

Examiner's Notes

  • 1 Mark: Correct math (price * 0.9) inside condition.

Level 2 Complete!

You have mastered the core algorithms. Ready for the final boss?

Start Level 3