while loop
For loop
Lists
100

What is the purpose of the while loop in Python?

To execute a block of code as long as a certain condition is true

100

What will be the output of the following code?

for i in range(3):

    print(i)


0 1 2

100

Which method is used to remove an element from a list by its value?



remove()

200

What will the following code print?

i = 1 

while i < 4:

  print(i)

  i += 1

The output will be:

1

2

3


200

Explain how the range() function works in a for loop. Provide an example.

The range() function generates a sequence of numbers, which can be used in a for loop to iterate a specific number of times.

for i in range(1, 10, 2):

    print(i)


200

What is the primary purpose of the extend() method?

Adds multiple elements to the end of a list

300

What is the correct way to avoid an infinite loop in the following code?

x = 10

while x > 0:

    print(x)


Add x = x - 1 inside the loop
(Reason: Decreasing x ensures the loop terminates when x reaches 0.)

300

Write a Python program that uses a for loop to print the squares of the numbers from 1 to 10.

for i in range(1, 11):

    print(i ** 2)


300

What does the append() method do in a list?

Adds a new item to the end of the list

400

What is the difference between using break and continue in a while loop?

  • break terminates the loop completely and transfers control to the first statement after the loop.
  • continue skips the rest of the code in the current iteration and jumps to the next iteration of the loop.
400

What will the following code output?

total = 0

for i in range(5):

    total += i

print(total)


10

400

What is the purpose of the elif statement?

To add another condition in an if-else structure



500

Who created the Python programming language

Python was created by Guido van Rossum in the late 1980s

500

When the 25th anniversary of SDU University was celebrated

2021

500

What was the route of the Titanic's first trip?

The Titanic's first trip was from Southampton in England to New York City in the USA.