Page 240 - Information_Practice_Fliipbook_Class11
P. 240

print("Logging out.")
                                  break

                              else:
                                  print("Invalid choice. Please enter a number between 1 and 4.")

                      else:
                          print("Incorrect admin credentials. Please try again.")

                  elif adminChoice == 2:
                      print("Quitting the program.")
                      break

                  else:
                      print("Invalid choice. Please enter a number between 1 and 2.")

              while True:
                   studentChoice  = int(input("\nStudent  Menu:\n1. Register\n2.  Play Quiz\n3. Quit\nEnter
                  your choice (1-3): "))

                  if studentChoice == 1:
                      studentName = input("Enter your name: ")

                  elif studentChoice == 2:
                      if quizData:
                          print("Available Categories: {}".format(", ".join(quizData.keys())))
                          selectedCategory = input("Enter the category you want to play: ")

                          if selectedCategory in quizData:
                              questions = quizData[selectedCategory]
                              score = 0

                              for question in questions:
                                  print(question['question'])
                                  for i, option in enumerate(question['options'], 1):
                                      print(f"{i}. {option}")

                                  userAnswer = int(input("Your answer (1-4): "))

                                  if userAnswer == question['correctAnswer']:
                                      print("Correct!")
                                      score += 1

                                  else:
                                       print("Incorrect. The correct answer is option
                                        {}.".format(question['correctAnswer']))


                              print("\n{}'s Final Score: {}/{}".format(studentName, score, len(questions)))

                          else:

          226  Touchpad Informatics Practices-XI
   235   236   237   238   239   240   241   242   243   244   245