#Project by: Annabella Nketia-Achiampong #Project name:To-Do list import random class ToDoList: MENU_CHOICES = { '1': 'Create a new task', '2': 'See your existing tasks', '3': 'Remove a completed task', '4': 'Complete a random task', '5': 'Exit' } GAME_CHOICES = { '1': 'Number Guessing Game', '2': 'Trivia Game' } def __init__(self): self.tasks = [] def number_game(self): print('Welcome to the number guessing game') print("I'm thinking of a number from 1 to 100. Your goal is to guess it.") print('-----------------------------------') target_number = random.randint(1, 100) attempts = 0 while True: try: user_guess = int(input('Enter your guess (from 1 to 100): ')) attempts += 1 if user_guess == target_number: print(f'Congratulations! You guessed the number in {attempts} attempts.') print("You have completed your game reward.\n") return True elif user_guess < target_number: print('Too low! The number I am thinking of is higher than that.') else: print('Too high! The number I am thinking of is lower than that.') except ValueError: print('Invalid input! Please enter a valid number.') def trivia_game(self): country_trivia = [ { 'question': 'What is the capital of Australia?', 'options': ['Sydney', 'Melbourne', 'Canberra', 'Perth'], 'answer': 'Canberra' }, { 'question': 'Which country is known as the Land of the Rising Sun?', 'options': ['China', 'Japan', 'South Korea', 'Thailand'], 'answer': 'Japan' }, { 'question': 'Which country is home to the Eiffel Tower?', 'options': ['Germany', 'France', 'Italy', 'Spain'], 'answer': 'France' }, { 'question': 'What is the chemical symbol for Helium?', 'options': ['K', 'He', 'H'], 'answer': 'He' }, { 'question': 'What is the largest internal organ in the human body?', 'options': ['Liver', 'Skin', 'Large Intestines'], 'answer': 'Liver' } ] def ask_question(question_dict): print(question_dict['question']) random.shuffle(question_dict['options']) for i, option in enumerate(question_dict['options'], start=1): print(f"{i}. {option}") while True: try: user_answer = int(input('Enter the number corresponding to your answer: ')) index = user_answer - 1 user_choice = question_dict['options'][index] if user_choice == question_dict['answer']: print('Correct!') print("Congratulations! You have completed your game reward.\n") return True else: print(f"Sorry, that's incorrect! The correct answer is {question_dict['answer']}.") print("You have completed your game reward. Better luck next time.\n") return False except ValueError: print('Invalid input! Please enter a valid option number.') question = random.choice(country_trivia) return ask_question(question) def add_task(self): task = input("Create a new task: ") self.tasks.append(task) print("Your task has been created.\n") def view_tasks(self): if self.tasks: print("These are your current tasks:") for index, task in enumerate(self.tasks, start=1): print(f"{index}. {task}") print() else: print("You have no tasks to complete.") create_task = input("Would you like to create a new one? (yes/no): ") if create_task.lower() == 'yes': self.add_task() elif create_task.lower() == 'no': print("Goodbye!\n") else: print("Invalid input! Command canceled.\n") def remove_task(self): if self.tasks: self.view_tasks() while True: try: task_index = int(input("Enter the number of the task you would like to remove: ")) - 1 if 0 <= task_index < len(self.tasks): removed_task = self.tasks.pop(task_index) print(f"You have completed '{removed_task}' task.") print("You have earned a game reward.\n") self.choose_game() break else: print("The task number you have entered cannot be found. Please try again.\n") except ValueError: print('Invalid input! Please enter a valid number.\n') else: create_new_task = input("No tasks. Would you like to create a new one? (yes/no): ") if create_new_task.lower() == 'yes': self.add_task() elif create_new_task.lower() == 'no': print("Goodbye!\n") else: print("Invalid input! Command canceled.\n") def complete_random_task(self): if self.tasks: random_task = random.choice(self.tasks) print(f"Your randomly chosen task is '{random_task}'.") confirm = input("Do you want to complete this task? (yes/no): ") if confirm.lower() == 'yes': self.tasks.remove(random_task) print("Congratulations! You have earned a game reward.\n") self.choose_game() else: print("Task completion canceled.") else: print("No tasks to be completed.") create_task = input("Would you like to create a new one? (yes/no): ") if create_task.lower() == 'yes': self.add_task() elif create_task.lower() == 'no': print("Goodbye!\n") else: print("Invalid input! Command canceled.\n") def choose_game(self): print("Which game would you like to play?") for key, value in self.GAME_CHOICES.items(): print(f"{key}. {value}") while True: game_choice = input("Enter your choice (1-2): ") if game_choice in self.GAME_CHOICES: if game_choice == "1": if self.number_game(): break elif game_choice == "2": if self.trivia_game(): break else: print("Invalid input! Please enter a valid game choice.\n") def menu(self): print("~~~ YOUR TO-DO LIST ~~~\n") print("What would you like to do today?\n") for key, value in self.MENU_CHOICES.items(): print(f"{key}. {value}") def start(self): while True: self.menu() choice = input("Enter your choice (1-5): ") if choice == "1": self.add_task() elif choice == "2": self.view_tasks() elif choice == "3": self.remove_task() elif choice == "4": self.complete_random_task() elif choice == "5": print("Goodbye!") break else: print("Invalid choice! Please try again.\n") todo_list = ToDoList() todo_list.start()