hand cricket game in python

Solutions on MaxInterview for hand cricket game in python by the best coders in the world

showing results for - "hand cricket game in python"
Liam
26 Apr 2016
1import random
2
3lst1= [1,2,3,4,5,6,7,8,9,10]
4
5chances_1= 20
6no_of_chances_1= 0
7your_runs= 0
8 
9print ("-----------------------------------------------\nYour Batting\n")
10while no_of_chances_1 < chances_1:
11    
12    runs= int(input("Enter Runs for Your Batting Turn: "))
13    comp_bowl= random.choice(lst1)
14
15    if runs==comp_bowl:
16        print ("Your Guess: ",runs,",Computer Guess: ",comp_bowl)
17        print ("You are Out. Your Total Runs= ", your_runs,"\n")
18        break
19    elif runs>10:
20        print ("ALERT!! Support No only till 10\n")
21        continue
22    else:
23        your_runs= your_runs+runs
24        print ("Your Guess: ",runs,",Computer Guess: ",comp_bowl)
25        print ("Your runs Now are: ",your_runs,"\n")
26
27    no_of_chances_1= no_of_chances_1 + 1  
28
29lst2= [1,2,3,4,5,6,7,8,9,10]
30
31chances_2= 20
32no_of_chances_2= 0
33comp_runs= 0
34print ("-----------------------------------------------")
35print ("Computer Batting-\n")
36while no_of_chances_2 < chances_2:
37
38    bowl= int(input("Enter Runs for Your Bowling Turn: "))
39    comp_bat= random.choice(lst2)
40
41    if comp_bat==bowl:
42        print ("Computer Guess: ",comp_bat,"Your Guess: ",bowl)
43        print ("The Computer is Out. Computer Runs= ",comp_runs,"\n")
44        break
45    else:
46        comp_runs= comp_runs+comp_bat
47        print ("Computer Guess: ",comp_bat,"Your Guess: ",bowl)
48        print ("Computer Runs: ",comp_runs,"\n")
49
50        if comp_runs > your_runs:
51            break
52        
53    no_of_chances_2= no_of_chances_2+1
54
55
56print ("\n-----------------------------------------------\nRESULTS: ")
57
58if comp_runs < your_runs:
59    print ("\nYou won the Game.\n\nYour Total Runs= ",your_runs,"  [Bowls taken(Out of 20): ",no_of_chances_1+1,"]","\nComputer Total Runs= ",comp_runs,"  [Bowls Taken(Out of 20): ",no_of_chances_2+1,"]\n")
60
61elif comp_runs == your_runs:
62    print ("The Game is a Tie")
63
64else:
65    print ("\nComputer won the Game.\n\nComputer Total Runs= ",comp_runs,"  [Bowls Taken(Out of 20): ",no_of_chances_2+1,"]","\nYour Total Runs= ",your_runs,"  [Bowls taken(Out of 20): ",no_of_chances_1+1,"]\n")