Page 239 - Information_Practice_Fliipbook_Class11
P. 239

print("2. Modify Question")
                                  print("3. Delete Question")
                                  print("4. Logout")
                                  adminOperation = int(input("Enter your choice (1-4): "))

                                  if adminOperation == 1:
                                      category = input("Enter the category for the question: ")
                                      question = input("Enter the question: ")
                                      options = [input("Enter option {}: ".format(i + 1)) for i in range(4)]
                                      correctAnswer = int(input("Enter the correct answer (1-4): "))

                                      if category not in quizData:
                                          quizData[category] = []


                                      quizData[category].append({
                                          'question': question,
                                          'options': options,
                                          'correctAnswer': correctAnswer
                                      })

                                  elif adminOperation == 2:
                                      category = input("Enter the category of the question to modify: ")
                                      if category in quizData:
                                           questionIndex = int(input("Enter the index of the question to modify
                                            (1-{}): ".format(len(quizData[category])))) - 1
                                          if 0 <= questionIndex < len(quizData[category]):
                                              question = quizData[category][questionIndex]
                                              print("Current Question: {}".format(question['question']))
                                              newQuestion = input("Enter the modified question: ")
                                              question['question'] = newQuestion
                                              print("Question modified successfully.")
                                          else:
                                              print("Invalid question index.")
                                      else:
                                          print("Category not found.")

                                  elif adminOperation == 3:
                                      category = input("Enter the category of the question to delete: ")
                                      if category in quizData:
                                           questionIndex = int(input("Enter the index of the question to delete
                                            (1-{}): ".format(len(quizData[category])))) - 1
                                          if 0 <= questionIndex < len(quizData[category]):
                                              del quizData[category][questionIndex]
                                              print("Question deleted successfully.")
                                          else:
                                              print("Invalid question index.")
                                      else:
                                          print("Category not found.")

                                  elif adminOperation == 4:


                                                                                             Python Dictionaries  225
   234   235   236   237   238   239   240   241   242   243   244