SHS Computing · Year 2
Python Functions, Conditions, Loops and Recursion practice questions
Variable naming rules and snake_case, primitive and complex data types, comments, defining and calling functions with parameters and return values, arithmetic including modulus, comparison and logical operators, if, if-else and if-elif-else statements, for loops with range, while loops, recursion and base cases, and building a simple calculator.
25 questions in this topic: 2 recall, 6 applying skills and concepts, 14 strategic thinking and 3 extended thinking. Every one carries a written explanation.
Sample questions
5 of 25 questions in this topic. Sign up to answer them and see the explanations.
- Question 1Skills & concepts
When is a while loop more suitable than a for loop?
- aWhen a task must be repeated exactly ten times, such as printing the numbers 1 to 10
- bWhen the number of repetitions is not known in advance, such as asking until a correct password is typed
- cWhen the program must loop through every single item of a list in order from the first one to the last
- dWhen the loop must never stop, since for loops cannot be used without a range at all
- Question 2Strategic thinking
Score = 85. The code is: if Score > 50: print("pass") elif Score > 80: print("merit") else: print("fail"). What is printed?
- amerit
- bpass
- cpass and merit
- dfail
- Question 3Strategic thinking
What does this code output? x = 15; print(x % 2 == 0)
- aTrue
- b1
- cFalse
- d7
- Question 4Skills & concepts
Which variable name follows Python's snake_case style?
- aTotalPrice
- btotal price
- ctotal-price
- dtotal_price
- Question 5Strategic thinking
What does this code output? n = 1; while n < 20: n = n * 3; then print(n)
- a27
- b9
- c18
- d20
Answer these and 20 more on Python Functions, Conditions, Loops and Recursion
Free account. Instant marking, a written explanation for every question.
Start practising freeMore Computing Year 2 topics
- Barcodes, QR Codes and the Functions of Software
- Designing LANs, CANs, MANs and WANs
- Internet Protocols, Addressing and Internet Access
- Logic Gates, Boolean Expressions and Arithmetic
- Machine Learning Concepts and Ethics
- Main Memory, Trees, Graphs and Hash Tables
- Multimedia, Responsive Design, Accessibility and E-commerce
- Relational Databases and SQL
- Web Page Editors, HTML and CSS