Reset while loop conditions in python to "play the quiz again" -
i'm still new @ this. essentially, need code reset while loop.
when user reaches end of quiz, asks if user play again. if user inputs y
quiz should restart.
my code:
print("moose quiz") question = 0 # tells questions user has completed questions = ["what average life span of moose?: ", "how moose eat on daily basis?: ", "the fastest moose ran...?: "] useranswers = ["","",""] # stores users answers answers = ["a. 10 - 14 years\nb. 15 - 25 years\nc. blue\nd. 26 - 35 years\n", "a. 24 lbs day\nb. 39 lbs day\nc. 67 lbs day\nd. 73 lbs day", "a. 20 mph\nb. 25 mph\nc. 35 mph\nd. 40 mph"] correct = 0 while question < 3: print(questions[question]) print(answers[question]) answers[question] = input("to answer, pick letter or leave blank skip it: ").lower() if question == 0: if answers[question] == "a": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "b": print() print("good job! correct.") correct = correct + 1 question = question + 1 print() elif answers[question] == "c": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "d": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "": print("awww...you skipped one!") question = question + 1 print() else: print("invalid character, please try again.") elif question == 1: if answers[question] == "a": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "b": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "c": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "d": print() print("terrific! got right!") correct = correct + 1 question = question + 1 print() elif answers[question] == "": print("awww...you skipped one!") question = question + 1 print() else: print("invalid character, please try again.") elif question == 2: if answers[question] == "a": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "b": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "c": print() print("amazing! you're awesome!") correct = correct + 1 question = question + 1 print() elif answers[question] == "d": print() print("sorry, please try again.") question = question + 1 print() elif answers[question] == "": print("awww...you skipped one!") question = question + 1 print() print("thanks playing!") again = input("would play again?: ")
at end, can reset question 0
while question < 3: ... again = input("would play again?: ") if again == 'y': question = 0
Comments
Post a Comment