
NUMBER GUESSING GAME
1.Show an option to get the details from the leaderboard db. 2.And find a way to sort it based on difficulty and attempts(Either descending or ascending). CODE: `leaderboard = [ {"name": "Alice", "difficulty": "Easy", "attempts": 3}, {"name": "Bob", "difficulty": "Hard", "attempts": 7}, {"name": "Charlie", "difficulty": "Medium", "attempts": 5}, {"name": "David", "difficulty": "Easy", "attempts": 2} ] difficulty_order = {"Easy": 1, "Medium": 2, "Hard": 3} def show_leaderboard(data): print("\n--- Leaderboard ---") for player in data: print(f"{player['name']} | {player['difficulty']} | Attempts: {player['attempts']}") def sort_by_attempts(data, reverse=False): return sorted(data, key=lambda x: x["attempts"], reverse=reverse) def sort_by_difficulty(data, reverse=False): return sorted(data, key=lambda x: difficulty_order[x["difficulty"]], reverse=reverse) while True: print("\n1. Show Leaderboard") print("2. Sort by Attempts (Ascending)") print("3. Sort by Attempts (Descending)") print("4.
Continue reading on Dev.to Tutorial
Opens in a new tab



