0

Please, could someone explain this code ?

true = 1 false = 0 def get_questions(): return [["What color is the daytime sky on a clear day?","blue"],\ ["What is the answer to life, the universe and everything?","42"],\ ["What is a three letter word for mouse trap?","cat"]] def check_question(question_and_answer): question = question_and_answer[0] answer = question_and_answer[1] given_answer = raw_input(question) if answer == given_answer: print "Correct" return true else: print "Incorrect, correct was:",answer return false def run_test(questions): if len(questions) == 0: print "No questions were given." return index = 0 right = 0 while index < len(questions): if check_question(questions[index]): right = right + 1 index = index + 1 print "You got ",right*100/len(questions),"% right out of",len(questions) run_test(get_questions())

4th Jan 2019, 6:49 PM
Aimen
2 odpowiedzi
0
Which part don't you understand?
4th Jan 2019, 10:10 PM
Diego
Diego - avatar
0
I don't understand why at the 2nd "def" in the ( ) it is written question_and_answer. Nonethless I think that is all a question about local and global variables. Please correct me if I'm wrong.
4th Jan 2019, 10:16 PM
Aimen