Set 1 Q and A
Set 1 Q and A
Questions
Programming Theory Questions
1. State what is meant by the term 'sequence' in programming. [1 mark]
2. Explain the difference between a 'while loop' and a 'for loop'. [2 marks]
3. What is the purpose of a selection statement in programming? [1 mark]
4. Explain what is meant by the term 'iteration' and give an example of when it might be
used in a program. [3 marks]
5. State two ways data can be validated in a program. [2 marks]
6. Explain what is meant by a 'variable' in programming and why they are important. [2
marks]
7. Describe what is meant by 'string concatenation' and provide an example. [2 marks]
8. Explain the purpose of functions/subroutines in programming. [2 marks]
score = 0
for i in range(10):
answer = input("Enter your answer: ")
if answer == "correct":
# Code missing here
print("Your final score is", score)
Complete the code to add 1 to the score whenever the user enters "correct". [1 mark]
number = INTEGER(INPUT)
total = 0
WHILE number > 0
total = total + number
number = number - 1
ENDWHILE
OUTPUT total
If the user enters 5, what will be output by this program? Show your working. [3 marks]
x = mystery(15, 7)
y = mystery(4, 10)
print(x + y)
What will be displayed when this code is executed? Explain your answer. [3 marks]
12. A programmer has written the following pseudocode to check if a number is a prime
number:
number = INTEGER(INPUT)
prime = TRUE
FOR i = 2 TO number - 1
IF number MOD i == 0 THEN
prime = FALSE
ENDIF
NEXT i
IF prime == TRUE THEN
OUTPUT "Prime number"
ELSE
OUTPUT "Not a prime number"
ENDIF
Trace through this algorithm step by step when the input is 7. [4 marks]