Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

What will be the output of this code? for i in range(3): print(i) else: print("Done")

View

What is the purpose of the iter() function?

View

What will be the output of this code? for i in [1, 2, 3]: for j in [4, 5]: print(i + j)

View

Which of the following methods returns the next item from an iterator?

View

What will be the output of this code? my_list = [1, 2, 3]; my_iter = iter(my_list); print(next(my_iter))

View

Which of the following is NOT a valid way to iterate over a list?

View

What is the purpose of the break statement in a loop?

View

What is the output of this code? for x in range(5): if x == 3: break; print(x)

View

What is the output of this code? for i in range(2): for j in range(2): print(i, j)

View

How can you iterate over the keys of a dictionary?

View

What will be the output of this code? for i in range(3): print(i) else: print("Done")

0 1 2
0 1 2 Done
Done
Error

What is the purpose of the iter() function?

To create a new list
To return an iterator object
To convert a string to an integer
None of the above

What will be the output of this code? for i in [1, 2, 3]: for j in [4, 5]: print(i + j)

5 6 7
5 6 7 8
5 6 7 8 9
Error

Which of the following methods returns the next item from an iterator?

next()
get()
fetch()
item()

What will be the output of this code? my_list = [1, 2, 3]; my_iter = iter(my_list); print(next(my_iter))

1
[1, 2, 3]
Error
None

Which of the following is NOT a valid way to iterate over a list?

for item in list:
while item in list:
for index in range(len(list)):
for index, item in enumerate(list):

What is the purpose of the break statement in a loop?

To skip to the next iteration
To terminate the loop
To exit the program
None of the above

What is the output of this code? for x in range(5): if x == 3: break; print(x)

0 1 2
0 1 2 3
0 1 2 3 4
Error

What is the output of this code? for i in range(2): for j in range(2): print(i, j)

0 0 0 1 1 0 1 1
0 1 0 1 1 0 1 1
0 0 1 0 0 1 1 1
0 0 1 1

How can you iterate over the keys of a dictionary?

for key in my_dict:
for key in my_dict.keys():
Both a and b
None of the above