Python code for cricket game

Python code for cricket game
Some days ago I decided to make a hand cricket game with python ..and I wrote codes but didnt finished it that day and Ii was quiet busy for the following days and I forgot wat was the idea in my mind for the game and iam too lazy to read and make the idea again

So the point is iam giving my unfinished source code here u can develop it and if possible post it as a comment :D

source code
=========
import random
def mod(n):
    if n<0:
        n=n*(-1)
    return n

def bat():
    
    out=0
    score=0
    while out!=1:
        b=random.randint(1,6)
        ba=int(raw_input('Enter your choice 1-6:'))
        if ba<1 or ba>6:
            print 'You cheats!'
                
            exit
        if b==ba:
            out=1
            print 'Computer also opted for',b
            print 'You are out'
           
        else:
            print 'You scored ',ba
            score=score+ba
            print 'score:',score
    return score               
def bowl(sc):
    if sc!=999:
        score=0
        while score<=sc:
            bc=random.randint(1,6)
            bo=int(raw_input('Enter your choice 1-6:'))
            if ba<1 or ba>6:
                print 'You cheats!'
                exit
            if bc==bo:
                out=1
                print 'Computer also opted for',bc
                print 'Computer is out'
                print 'computer scores ',score,'runs'
                d=score-sc
                if d>0:
                    print 'computer won'
                elif d<1:
                    print 'computer lost by',mod(d),'runs'
                else:
                    print 'Match is a draw'
            
            else:
                print 'Computer scored ',ba
                score=score+ba
                print "Computer's score:",score
                d2=sc-score
                if d2>0:
                    print 'computer needs ',d2+1,'runs to win'
                else                    
    return score        
            

do:
    print 'you can have 1-6 and one wicket'
    print 'Let us do the toss'
    t=random.randint(1,2)
    ch=str(raw_input('CHOOSE EVEN OR ODD(e/o):'))
    to=int(raw_input('ENTER YOUR NUMBER:'))
    toss=t+to
    print 'Computer:',t
    if toss%2==0:
        if ch=='e' or ch=='E':
            print 'You won the toss'
            u=1
        else:
            print 'You loss the toss'
            u=0
    else:
        if ch=='o' or ch=='O':
            print 'You won the toss'
            u=1
        else:
            print 'You loss the toss'
            u=0
    if u==1:
        d=int(raw_input('1.Bat or 2.Bowl?(1/2):'))
        if d==1:
            score1=bat()
            score2=bowl(score1)
        else:
            bowl(1)
    else:
        d=random.randint(1,2)
        if d==1:
            print 'computer choose to bat first!'
            bat(0)
        else:
            print 'Computer choose to bowl first!'
            bowl(0)
    pl=str(raw_input('DO you wish to play again?(y/n):'))
while pl=='y' or pl=='Y'    



Note: Add brackets in every print function. Eg: print ("if you don't understand python, don't do it.")


Note: Check out my vid in python here is the link
Part 1:https://www.youtube.com/watch?v=SG9e124ifnc&t=346s
Part 2:https://www.youtube.com/watch?v=MBejnwCooUw&t=96s

Comments

Popular Posts