Read more

import random import time print("=== Welcome to the Python Cricket Game ===") print("You will play a 1-over match (6 balls) against the computer!") print("Choose a number between 1 and 6 to play your shot. Let's go!\n") # Player bats first player_score = 0 print("You are batting first!") for ball in range(1, 7): player = int(input(f"Ball {ball} - Your shot (1-6): ")) comp = random.randint(1, 6) if player == comp: print(f"Out! Computer bowled {comp}.") break else: player_score += player print(f"You scored {player} runs. Total: {player_score}") print(f"\nInnings over! You scored {player_score} runs.\n") time.sleep(2) # Computer bats comp_score = 0 print("Computer is batting now. Try to bowl it out!") for ball in range(1, 7): player = int(input(f"Ball {ball} - Your bowl (1-6): ")) comp = random.randint(1, 6) if player == comp: print(f"Bowled! You guessed {player}, and computer played {comp}.") break else: comp_score += comp print(f"Computer scored {comp} runs. Total: {comp_score}") if comp_score > player_score: break print(f"\nMatch Over!") print(f"Your Score: {player_score}") print(f"Computer's Score: {comp_score}") if player_score > comp_score: print("Congratulations! You won!") elif player_score < comp_score: print("Computer wins! Better luck next time!") else: print("It's a tie!")