Title
QUESTIONS = {
"Which keyword do you use to loop over a given list of elements": [
"for", "while", "each", "loop"
],
"What's the purpose of the built-in zip() function": [
"To iterate over two or more sequences at the same time",
"To combine several strings into one",
"To compress several files into one archive",
"To get information from the user",
],
"What's the name of Python's sorting algorithm": [
"Timsort", "Quicksort", "Merge sort", "Bubble sort"
],
}
for question, alternatives in QUESTIONS.items():
correct_answer = alternatives[0]
sorted_alternatives = sorted(alternatives)
for label, alternative in enumerate(sorted_alternatives):
print(f" {label}) {alternative}")
answer_label = int(input(f"{question}? "))
answer = sorted_alternatives[answer_label]
if answer == correct_answer:
print("Correct!")
else:
print(f"The answer is {correct_answer!r}, not {answer!r}")