Course Hero Logo

multiple test.py - import random animals questions =...

This preview shows page 1 - 2 out of 2 pages.

import randomanimals_questions = 'Animals Questions'capitals_questions = 'Capitals Questions'math_questions = 'Math Questions'def main():questions = [animals_questions, capitals_questions, math_questions]quiz = {animals_questions: [(" Most ants are workers.", True), ("There are morebutterfly species than moth species in the United States.", False),("Indianelephants are larger than African elephants.", False)],capitals_questions: [("Cairo is the capital city of Egypt", True),("Brasília is the capital of Brazil", True), ("Sydney is the capital of Australia",False)],math_questions: [("20 is log 100 for base 1o", False), ("-2 is aninteger.", True), ("All sides of a scalene triangle have the same length.",False)]}choice = get_quiz_choice()quiz_name = questions[choice - 1]print ("\nYou chose the {}\n".format(quiz_name))quiz_questions = quiz[quiz_name]count = 0for question in (quiz_questions):if get_answer(question[0], question[1]):
End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
NoProfessor
Tags
triangle

Unformatted text preview: print("That's the correct answer") count +=1 else: print("That's incorrect") print(f"Your score: {count}") def get_quiz_choice(): while True: try: quiz_number = int(input('Choose the quiz you like\n1 for {}\n2 for {}\n3 for {}\nYour choice: '.format(animals_questions, capitals_questions, math_questions))) except ValueError: print("Not a number, please try again.\n") else: if quiz_number in [1, 2, 3]: return quiz_number else: print('Invalid value, please try it again.') print() def get_answer(question, correct_answer): while True: try: print("Q: {}".format(question)) answer = int(input("1 for True\n0 for False\nYour answer: ")) except ValueError: print ("Not a number, please try again\n") if answer not in [0,1]: print ("Invalid value, please try again\n") continue elif bool(answer) == correct_answer: return True elif bool(answer) != correct_answer: return False break if __name__ == "__main__": main()...
View Full Document

Newly uploaded documents

Show More

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture