BingoN'Lotto

mail@pastecode.io avatar
unknown
plain_text
a month ago
3.5 kB
0
Indexable
Never
import random

class LotteryBingoGame:
    def __init__(self):
        self.levels = ["Easy", "Medium", "Hard"]
        self.current_level = 0
        self.score = 0
        self.score_board = {}

    def generate_lottery_numbers(self):
        return random.sample(range(1, 51), 6)

    def generate_bingo_numbers(self):
        return random.sample(range(1, 76), 5)

    def play_lottery(self, user_numbers):
        winning_numbers = self.generate_lottery_numbers()
        matched_numbers, num_matches = self.check_results(winning_numbers, user_numbers)
        self.update_score(num_matches)
        self.display_results("Lottery", winning_numbers, user_numbers, matched_numbers)

    def play_bingo(self, user_numbers):
        winning_numbers = self.generate_bingo_numbers()
        matched_numbers, num_matches = self.check_results(winning_numbers, user_numbers)
        self.update_score(num_matches)
        self.display_results("Bingo", winning_numbers, user_numbers, matched_numbers)

    def check_results(self, winning_numbers, user_numbers):
        matched_numbers = set(winning_numbers) & set(user_numbers)
        return matched_numbers, len(matched_numbers)

    def update_score(self, num_matches):
        self.score += num_matches

    def display_results(self, game_type, winning_numbers, user_numbers, matched_numbers):
        print("\nResults for", game_type)
        print("Winning Numbers:", winning_numbers)
        print("Your Numbers:", user_numbers)
        print("Matched Numbers:", matched_numbers)
        print("Number of Matches:", len(matched_numbers))
        print("Current Score:", self.score)

    def play_game(self):
        print("Welcome to the Lottery and Bingo Game!")
        print("You will play both Lottery and Bingo. Each game has three levels.")
        print("Try to match as many numbers as possible to increase your score.")

        for level in self.levels:
            self.current_level += 1
            print("\nLevel", self.current_level, ":", level)

            # Play Lottery
            print("\nLottery:")
            user_lottery_numbers = self.get_user_numbers("Enter 6 numbers between 1 and 50: ")
            self.play_lottery(user_lottery_numbers)

            # Play Bingo
            print("\nBingo:")
            user_bingo_numbers = self.get_user_numbers("Enter 5 numbers between 1 and 75: ")
            self.play_bingo(user_bingo_numbers)

        print("\nGame Over!")
        print("Your Final Score:", self.score)

        # Update scoreboard
        player_name = input("Enter your name for the scoreboard: ")
        self.score_board[player_name] = self.score

        # Display scoreboard
        print("\nScoreboard:")
        for name, score in self.score_board.items():
            print(name + ":", score)

    def get_user_numbers(self, prompt):
        try:
            user_numbers = []
            for _ in range(6 if "Lottery" in prompt else 5):
                number = int(input(prompt))
                if 1 <= number <= 50 if "Lottery" in prompt else 75:
                    user_numbers.append(number)
                else:
                    print("Please enter a valid number.")
                    return self.get_user_numbers(prompt)
            return user_numbers
        except ValueError:
            print("Invalid input. Please enter valid numbers.")
            return self.get_user_numbers(prompt)

if __name__ == "__main__":
    game = LotteryBingoGame()
    game.play_game()
Leave a Comment