Untitled

A cricket game
 avatar
unknown
plain_text
5 months ago
1.0 kB
3
Indexable
def cricket_game_with_wickets():
    print("Welcome to the Cricket Game with Wickets!")
    total_score = 0
    wickets = 3  # Number of lives/wickets

    while wickets > 0:
        try:
            player_shot = int(input("Enter your shot (1-6): "))
            if player_shot < 1 or player_shot > 6:
                print("Invalid shot! Please choose a number between 1 and 6.\n")
                continue

            computer_ball = random.randint(1, 6)
            print(f"Computer bowled: {computer_ball}")

            if player_shot == computer_ball:
                wickets -= 1
                print(f"You're out! Wickets remaining: {wickets}")
            else:
                total_score += player_shot
                print(f"Good shot! Your score: {total_score}\n")

        except ValueError:
            print("Invalid input. Please enter a valid number between 1 and 6.\n")

    print(f"Game Over! Your total score: {total_score}")

if __name__ == "__main__":
    cricket_game_with_wickets()
Editor is loading...
Leave a Comment