| 3 | |
| 4 | |
| 5 | def main(): |
| 6 | print("Welcome Hand Cricket") |
| 7 | print("You will be playing against another player") |
| 8 | try: |
| 9 | overs = int(input("Enter the number of overs (1-10): ")) |
| 10 | |
| 11 | # Toss to decide who bats first |
| 12 | toss_winner = toss() |
| 13 | if toss_winner == 1: |
| 14 | print("Player 1 won the toss!") |
| 15 | player1_choice = input("Player 1, choose 1 to bat first, 2 to bowl first: ") |
| 16 | player2_choice = "1" if player1_choice == "2" else "2" |
| 17 | else: |
| 18 | print("Player 2 won the toss!") |
| 19 | player2_choice = input("Player 2, choose 1 to bat first, 2 to bowl first: ") |
| 20 | player1_choice = "1" if player2_choice == "2" else "2" |
| 21 | |
| 22 | difficulty = int(input("Select difficulty level (1-Easy, 2-Medium, 3-Hard): ")) |
| 23 | |
| 24 | # Call the play_game function with user inputs |
| 25 | player1_score, player2_score = play_game( |
| 26 | overs, player1_choice, player2_choice, difficulty |
| 27 | ) |
| 28 | |
| 29 | # Determine and display the winner |
| 30 | who_won(player1_score, player2_score) |
| 31 | except ValueError: |
| 32 | print("Invalid input, exiting game") |
| 33 | |
| 34 | |
| 35 | # Function to handle the toss |