|
| 1 | + |
| 2 | +# List of questions for quiz |
| 3 | + |
| 4 | +questions =[ |
| 5 | + |
| 6 | + 'who is the developer of Python Language', |
| 7 | + |
| 8 | + 'when did india gets independence', |
| 9 | + |
| 10 | + 'what is the Indian currency', |
| 11 | + |
| 12 | + 'Who is World first cloned human baby', |
| 13 | + |
| 14 | + 'who is the founder of Hinduism' |
| 15 | + |
| 16 | +] |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +# list of answers for above questions |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +answers = [ |
| 25 | + |
| 26 | + 'Guido Van', |
| 27 | + |
| 28 | + '1947', |
| 29 | + |
| 30 | + 'INR', |
| 31 | + |
| 32 | + 'Eve', |
| 33 | + |
| 34 | + 'No Specific' |
| 35 | + |
| 36 | +] |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +# List of options for above questions |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +options= [ |
| 45 | + |
| 46 | + ['Dennis Ritchie','Alan Frank','Guido Van','Albert'], |
| 47 | + |
| 48 | + ['1947','1995','1950','1957'], |
| 49 | + |
| 50 | + ['DOLLARS','YEN','EURO','INR'], |
| 51 | + |
| 52 | + ['Erik','Maria','Sophie','Eve'], |
| 53 | + |
| 54 | + ['Mahavira Swami','Mahatma Buddha','No Specific','Prophet Mohammed'] |
| 55 | + |
| 56 | +] |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +# Quiz Game | Designed by Ishita |
| 61 | + |
| 62 | + |
| 63 | + |
| 64 | +# Defining function for game playing |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | +def play_game(username,questions,answers,options): |
| 69 | + |
| 70 | + print("Hello,", username, "welcome to the QUIZ game") |
| 71 | + |
| 72 | + print("All the Best for the Game :>") |
| 73 | + |
| 74 | + score = 0 |
| 75 | + |
| 76 | + for i in range(5): |
| 77 | + |
| 78 | + current_questions = questions[i] |
| 79 | + |
| 80 | + # print(questions[i]) |
| 81 | + |
| 82 | + correct_answer = answers[i] |
| 83 | + |
| 84 | + current_question_options = options[i] |
| 85 | + |
| 86 | + print("Questions:" ,current_questions) |
| 87 | + |
| 88 | + for index,each_options in enumerate(current_question_options): |
| 89 | + |
| 90 | + print(index+1,") ",each_options,sep='') |
| 91 | + |
| 92 | + user_answer_index = int(input("Please enter your choice(1,2,3,4): ")) |
| 93 | + |
| 94 | + user_answer = current_question_options[user_answer_index-1] |
| 95 | + |
| 96 | + if user_answer== correct_answer: |
| 97 | + |
| 98 | + print("correct answer") |
| 99 | + |
| 100 | + score = score +100 |
| 101 | + |
| 102 | + else: |
| 103 | + |
| 104 | + print("wrong answer") |
| 105 | + |
| 106 | + break |
| 107 | + |
| 108 | + print("Your final score is", score) |
| 109 | + |
| 110 | + return username,score |
| 111 | + |
| 112 | + |
| 113 | + |
| 114 | +# Defining function for viewing the score |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +def view_scores(names_and_scores): |
| 119 | + |
| 120 | + for name,score in names_and_scores.items(): |
| 121 | + |
| 122 | + print(name,"has scored",score) |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +# Defining the function for start of the game |
| 127 | + |
| 128 | + |
| 129 | + |
| 130 | +def quiz(questions,answers,options): |
| 131 | + |
| 132 | + |
| 133 | + |
| 134 | + names_and_scores = {} |
| 135 | + |
| 136 | + while True: |
| 137 | + |
| 138 | + print("Welcome to the quiz game") |
| 139 | + |
| 140 | + print("1) Play\n2) View Scores\n3) Exit") |
| 141 | + |
| 142 | + choice=int(input("Please enter your choice: ")) |
| 143 | + |
| 144 | + if choice == 1: |
| 145 | + |
| 146 | + username =(input("Please enter your name: ")) |
| 147 | + |
| 148 | + username,score = play_game(username,questions,answers,options) |
| 149 | + |
| 150 | + names_and_scores[username] = score |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + elif choice ==2: |
| 157 | + |
| 158 | + view_scores(names_and_scores) |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | + elif choice ==3: |
| 163 | + |
| 164 | + break |
| 165 | + |
| 166 | + |
| 167 | + |
| 168 | + else : |
| 169 | + |
| 170 | + print("Your choice is not correct") |
| 171 | + |
| 172 | + |
| 173 | + |
| 174 | +# Program execution starts from here |
| 175 | + |
| 176 | + |
| 177 | + |
| 178 | +quiz(questions,answers,options) |
0 commit comments