from random import * #random is a library. we need the randint function from it def Main() : Questions = [] # list of all the questions Answers = [] # list of all the answers setup(Questions, Answers) while True : target = int(input("How many questions for your quiz game? ")) if target <= len(Questions) : break print("Sorry, I only have ", len(Questions), " in my databank") # alternate version: # target = int(input("How many questions for your quiz game? ")) # while target > len(Questions) : # print("Sorry, I only have ", len(Questions), " in my databank") # target = int(input("How many questions for your quiz game? ")) score = 0 numberAsked = 0 while len(Questions) > 0 : qnNum = randint(0, len(Questions)-1) correct = askQuestion(Questions[qnNum], Answers[qnNum]) numberAsked = numberAsked + 1 if correct == "quit" : break elif correct : score=score+1 del Questions[qnNum] del Answers[qnNum] reportScore(score, numberAsked) def reportScore(sc, numAsked) : len(print("Well done! You got ", sc, " questions right out of ", numAsked)) #asks the user a question, and returns True or False depending on whether they answered correctly. # If the user answered with 'q', then it should return "quit" def askQuestion (question, correctAnswer): print(question) answer = input("your answer: ").lower() if answer == "quit" : return "quit" elif answer == correctAnswer.lower() : print("you got it right!") return True else : print("No, that's wrong. The correct answer is ", correctAnswer) return False # Sets up the lists of questions def setup(Questions, Answers) : Questions.append("Who is the youngest singer in One Direction?") Answers.append("Harry") Questions.append("Who is the oldest singer in One Direction?") Answers.append("Zack") Main()