Apr-30-2018, 10:08 PM
Hello,
Kindly help me with the following. I am still trying to figure out loops and the While statement. Please tell me how to go about code for the following question and why my code is wrong. It is from the edx (Microsoft) online course.
Thanks.
Question
create a function: quiz_item() that asks a question and tests if input is correct
quiz_item()has 2 parameter strings: question and solution
shows question, gets answer input
returns True if answer == solution or continues to ask question until correct answer is provided
use a while loop
create 2 or more quiz questions that call quiz_item()
Hint: provide multiple choice or T/F answers
My code
Kindly help me with the following. I am still trying to figure out loops and the While statement. Please tell me how to go about code for the following question and why my code is wrong. It is from the edx (Microsoft) online course.
Thanks.
Question
create a function: quiz_item() that asks a question and tests if input is correct
quiz_item()has 2 parameter strings: question and solution
shows question, gets answer input
returns True if answer == solution or continues to ask question until correct answer is provided
use a while loop
create 2 or more quiz questions that call quiz_item()
Hint: provide multiple choice or T/F answers
My code
def quiz(question, solution): answer = input("State the solution to the quiz: ") if answer == solution: return True else: print("Wrong Answer!\nTry again...\n") answer = input("State the solution to the quiz: ") while quiz(question, solution) == False: print("Wrong Answer!\nTry again...\n")