11import random
22
3+
34def get_user_choice ():
45 while True :
56 try :
@@ -11,6 +12,7 @@ def get_user_choice():
1112 except ValueError :
1213 print ("Invalid input. Please enter a number between 1 and 6." )
1314
15+
1416def play_innings (player , overs , max_wickets ):
1517 runs = 0
1618 wickets = 0
@@ -35,7 +37,9 @@ def play_innings(player, overs, max_wickets):
3537 if balls % 6 == 0 :
3638 over_number = balls // 6
3739 print (f"End of Over { over_number } " )
38- print (f"Over { over_number } Summary: { player } scored { runs } runs with { wickets } wickets." )
40+ print (
41+ f"Over { over_number } Summary: { player } scored { runs } runs with { wickets } wickets."
42+ )
3943
4044 print (f"Total Score: { runs } /{ wickets } " )
4145 print (f"Balls remaining: { overs * 6 - balls } " )
@@ -52,16 +56,23 @@ def play_innings(player, overs, max_wickets):
5256
5357 return runs , wickets
5458
59+
5560print ("~ Welcome to the Game of Cricket ~" )
5661
5762print ("\n Instructions:" )
5863print ("1. You have to select any number from 1 to 6." )
5964print ("2. The computer will also select a number." )
60- print ("3. While batting, if your number and computer's number are different, you'll add to your runs." )
65+ print (
66+ "3. While batting, if your number and computer's number are different, you'll add to your runs."
67+ )
6168print (" If they are the same, you'll lose a wicket." )
62- print ("4. While bowling, if your number and computer's number are different, the computer adds to its runs." )
69+ print (
70+ "4. While bowling, if your number and computer's number are different, the computer adds to its runs."
71+ )
6372print (" If they are the same, the computer loses a wicket." )
64- print ("5. Each player will get 2 wickets and 2 overs (12 balls) for batting and bowling." )
73+ print (
74+ "5. Each player will get 2 wickets and 2 overs (12 balls) for batting and bowling."
75+ )
6576print ("6. The innings will end after either three wickets fall or the overs end." )
6677print ("7. The player with the maximum runs wins." )
6778
@@ -81,7 +92,9 @@ def play_innings(player, overs, max_wickets):
8192 computer_choice = random .choice (["bat" , "bowl" ])
8293 user_choice = "bowl" if computer_choice == "bat" else "bat"
8394
84- print (f"{ toss_winner } chose to { user_choice } and the computer chose to { computer_choice } " )
95+ print (
96+ f"{ toss_winner } chose to { user_choice } and the computer chose to { computer_choice } "
97+ )
8598
8699user_runs , user_wickets = play_innings ("You" , 2 , 2 )
87100computer_runs , computer_wickets = play_innings ("Computer" , 2 , 2 )
@@ -93,6 +106,8 @@ def play_innings(player, overs, max_wickets):
93106if user_runs > computer_runs :
94107 print (f"Congratulations! You won the Match by { user_runs - computer_runs } runs." )
95108elif user_runs < computer_runs :
96- print (f"Better luck next time! The Computer won the Match by { computer_runs - user_runs } runs." )
109+ print (
110+ f"Better luck next time! The Computer won the Match by { computer_runs - user_runs } runs."
111+ )
97112else :
98113 print ("The Match is a Tie. No one Wins." )
0 commit comments