Translate a procedure
Beginner · Write the code · from Exam Pseudocode in Python: Every Construct Side by Side
From the lesson: Exam Pseudocode in Python: Every Construct Side by Side
The Computer Science Principles exam writes its code questions in its own pseudocode, so the fastest way to read them is to know exactly how each line would look in Python, and where the two languages quietly disagree.
Read the lessonTranslate this pseudocode into a Python function count_above(values, limit):
PROCEDURE countAbove(values, limit)
{
count ← 0
FOR EACH v IN values
{
IF (v > limit)
{
count ← count + 1
}
}
RETURN (count)
}def count_above(values, limit):
# Your code here
pass
What Check runs
Your code runs first, then each of these lines, and 2 more that stay hidden. The output must match exactly.
| Runs | Expected output |
|---|---|
| count_above([3, 8, 12, 5], 4) | 3 |
| count_above([1, 2], 10) | 0 |
More Pseudocode exercises
- INSERT with exam rulesIntermediate