Programming Basics
Selection
Iteration
Operators & Expressions
Sequencing & Basic Algorithm Thinking
100

What is a variable?

A named location in memory that stores a value.

100

What keyword starts a decision in Python?

Answer: if

100

Which loop repeats a set number of times:

for loop

100

What is a comparison operator?

An operator that compares two values, such as ==, >, <.

100

What does sequencing mean in programming?

Running instructions in order, one after another.

200

In Python, what data type does input() return?

It always returns a string.

200

Fill in the missing keyword:

elif

200

What will this code output?

It prints Hi three times.

200

What does the expression 5 % 2 evaluate to?

Answer: 1, because it gives the remainder.

200

Why do programmers use comments in their code?

To explain what the code does and make it easier to read.

300

What does assignment mean in programming?

Giving a variable a value using the equals sign.

300

What does an elif allow a program to do?

Check another condition if the previous one was false.

300

Give an example of something that could cause an infinite loop.

A while loop whose condition never becomes false (e.g., forgetting to update a variable inside the loop).

300

Why is >= different from >?

Answer: >= checks if a value is greater than or equal; > checks only greater than.

300

Put these steps in correct sequence:

  • 1. Ask for the user’s name

  • 2. Print a greeting

  • 3. Store the name in a variable

 

1 → 3 → 2

400

What is the difference between an integer and a float?

An integer has no decimal places; a float is a number with decimals.

400

Why is indentation important in Python selection?

It tells Python which lines belong to the IF statement’s block of code.

400

What is the main difference between a for loop and a while loop?

A for loop repeats a fixed number of times; a while loop repeats until a certain condition is met. 

400

What is the difference between / and // in Python?

/ gives a float (normal division), while // gives integer division and removes the decimal part.

400

Describe an algorithm to add two numbers input by the user

Ask for the first number, ask for the second number, convert them to integers, add them together, and output the result.

500

 Explain why this code causes an error:

age is a string, so you can’t add it to an integer without converting it

500

Explain what a nested IF is and give an example of when you might need

A nested IF is an IF statement placed inside another. You might use it when checking two conditions one after the other, such as checking if someone passed an exam and then checking for a merit grade.

500

 Explain the logical problem in the loop below and suggest one fix.

The password never changes inside the loop, so it repeats forever. You need to add password = input("Enter password: ") inside the loop.

500

Explain why this expression produces an error:


You can’t join a string and an integer using +.



500

This program is supposed to add up 4 numbers entered by the user and then display the total. What is the problem with the code? 

Inside the loop, total is being replaced with number each time instead of adding to it. It should use total += number so the values are accumulated.