|
| 1 | + |
| 2 | +# List of questions for quiz |
| 3 | + |
| 4 | +questions =[ |
| 5 | +'who is the developer of Python Language', |
| 6 | +'when did india gets independence', |
| 7 | +'what is the Indian currency', |
| 8 | +'Who is World first cloned human baby', |
| 9 | +'who is the founder of Hinduism' |
| 10 | +] |
| 11 | + |
| 12 | +# list of answers for above questions |
| 13 | + |
| 14 | +answers = [ |
| 15 | +'Guido Van', |
| 16 | +'1947', |
| 17 | +'INR', |
| 18 | +'Eve', |
| 19 | +'No Specific' |
| 20 | +] |
| 21 | + |
| 22 | +# List of options for above questions |
| 23 | + |
| 24 | +options= [ |
| 25 | +['Dennis Ritchie','Alan Frank','Guido Van','Albert'], |
| 26 | +['1947','1995','1950','1957'], |
| 27 | +['DOLLARS','YEN','EURO','INR'], |
| 28 | +['Erik','Maria','Sophie','Eve'], |
| 29 | +['Mahavira Swami','Mahatma Buddha','No Specific','Prophet Mohammed'] |
| 30 | +] |
| 31 | + |
| 32 | +# Quiz Game | Designed by Ishita |
| 33 | + |
| 34 | +# Defining function for game playing |
| 35 | + |
| 36 | +def play_game(username,questions,answers,options): |
| 37 | +print("Hello,", username, "welcome to the QUIZ game") |
| 38 | +print("All the Best for the Game :>") |
| 39 | +score = 0 |
| 40 | +for i in range(5): |
| 41 | +current_questions = questions[i] |
| 42 | +# print(questions[i]) |
| 43 | +correct_answer = answers[i] |
| 44 | +current_question_options = options[i] |
| 45 | +print("Questions:" ,current_questions) |
| 46 | +for index,each_options in enumerate(current_question_options): |
| 47 | +print(index+1,") ",each_options,sep='') |
| 48 | +user_answer_index = int(input("Please enter your choice(1,2,3,4): ")) |
| 49 | +user_answer = current_question_options[user_answer_index-1] |
| 50 | +if user_answer== correct_answer: |
| 51 | +print("correct answer") |
| 52 | +score = score +100 |
| 53 | +else: |
| 54 | +print("wrong answer") |
| 55 | +break |
| 56 | +print("Your final score is", score) |
| 57 | +return username,score |
| 58 | + |
| 59 | +# Defining function for viewing the score |
| 60 | + |
| 61 | +def view_scores(names_and_scores): |
| 62 | +for name,score in names_and_scores.items(): |
| 63 | +print(name,"has scored",score) |
| 64 | + |
| 65 | +# Defining the function for start of the score |
| 66 | + |
| 67 | +def quiz(questions,answers,options): |
| 68 | +names_and_scores = {} |
| 69 | +while True: |
| 70 | +print("Welcome to the quiz game") |
| 71 | +print("1) Play\n2) View Scores\n3) Exit") |
| 72 | +choice=int(input("Please enter your choice: ")) |
| 73 | +if choice == 1: |
| 74 | +username =(input("Please enter your name: ")) |
| 75 | +username,score = play_game(username,questions,answers,options) |
| 76 | +names_and_scores[username] = score |
| 77 | +elif choice ==2: |
| 78 | +view_scores(names_and_scores) |
| 79 | +elif choice ==3: |
| 80 | +break |
| 81 | +else : |
| 82 | +print("Your choice is not correct") |
| 83 | + |
| 84 | +# Program execution starts from here |
| 85 | + |
| 86 | +quiz(questions,answers,options) |
0 commit comments