Aug-31-2022, 10:54 AM
This code:
If I change the code to this:
quiz = ( ("What is the capital of France?", "PARIS") ("What is the capital of Germany?", "BERLIN") ) score = 0 for index, question in (quiz): q, a = question print(f"Question {index+1} : {q}") if input("Answer? ").upper() == a: score += 1 print('Correct!') else: print(f"Incorrect :(\nThe correct answer is: {a}") print(f"Your score is {score}")...even with a correction to the syntax (a missing comma in the nested tuple), I can't see how it's going to work.
If I change the code to this:
quiz = ( ("What is the capital of France?", "PARIS"), ("What is the capital of Germany?", "BERLIN") ) score = 0 for index, question in enumerate(quiz): q, a = question print(f"Question {index+1} : {q}") if input("Answer? ").upper() == a: score += 1 print('Correct!') else: print(f"Incorrect :(\nThe correct answer is: {a}") print(f"Your score is {score}"))... then yes, it works fine, and is a nice, simple way to do this.
Sig:
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
>>> import this
The UNIX philosophy: "Do one thing, and do it well."
"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse
"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein