HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Problems
  2. /This algorithm adds up positive numbers until it has three of them…
HardComputer ScienceHigh School (9–10)Computer Science › Algorithms and Problem-SolvingNumericalIGCSE

This algorithm adds up positive numbers until it has three of them…

StemPy LabContributed by StemPy Lab

Try it on paper first. A hint, the key idea and the worked solution are here when you need them.

This algorithm adds up positive numbers until it has three of them. It shows a prompt before each input.

pseudocode
Count ← 0
Sum ← 0
REPEAT
    OUTPUT "Enter a number"
    INPUT Num
    IF Num > 0
      THEN
        Sum ← Sum + Num
        Count ← Count + 1
    ENDIF
UNTIL Count = 3
OUTPUT "Sum: ", Sum

Complete a trace table with the columns Count, Sum, Num and OUTPUT for the inputs 444, −2-2−2, 666, 000, 555. How many times is the prompt output, and what is the final value of Sum?

Check your answer

Work it out on paper, then type your number. The answer itself stays hidden.

Need a reminder? The key ideaShowHide

A dry run follows an algorithm by hand. A trace table has a column for each variable and for the output, which includes the user prompts. Write a value only when it changes, and start a new row for each pass of a loop.

The worked solution

Have you tried it?

Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.

Step 1. Start. Count 000, Sum 000.

Step 2. The passes. Each pass starts a new row with the prompt in the OUTPUT column.

A trace table with the columns Count, Sum, Num and OUTPUT. First row: Count 0, Sum 0. Then one row for each prompt "Enter a number": Num 4 with Sum 4 and Count 1; Num -2; Num 6 with Sum 10 and Count 2; Num 0; Num 5 with Sum 15 and Count 3. Last row: OUTPUT "Sum: 15".
  • Input 444: positive, so Sum 444, Count 111.
  • Input −2-2−2: not positive, no change.
  • Input 666: Sum 101010, Count 222.
  • Input 000: not positive, no change.
  • Input 555: Sum 151515, Count 333. Now Count = 3, so the loop stops.

Step 3. Output. Sum: 15.

Answer: the prompt is output 555 times, once for each input, and Sum ends at 151515.

Check. Three positive numbers were added: 4+6+5=154 + 6 + 5 = 154+6+5=15.

Log in to save this for later
← All Problems
← Dry-run this algorithm and complete a trace table with the columns A, B and OUTPUT…Dry-run this algorithm with the input 586, and then state its purpose. →
More onComputer Science › Algorithms and Problem-Solving

Discussion (0)

Log in to join the discussion.

Loading…

Learn it in

  1. Trace tables and dry runsPseudocode, Trace Tables and Testing

More on this topic

  1. This is the kind of long scenario question that ends Paper 2…Hard
  2. A delivery company adds a check digit to each parcel number…Medium
  3. Name the check in each case. Say whether it is validation or verification…Easy
  4. A bubble sort is changed so that it sorts in descending order: the comparison becomes IF…
Hard
  • A shop stores the colours of the ten bicycles in its window in an array Colours: red, blue, red…Medium
  • All problems on this topic →