Sunday, October 23, 2016

HAND CRICKET GAME IN PYTHON

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'    



Thursday, October 6, 2016

A GUESS GAME WITH PYTHON

Hey friends ! I gonna give a source code in python for a guess game...the game is simple the computer thinks of a number between 1 and 50 and gives you six chances to guess it right and it gives u clue by telling if your guess was greater or lesser than the number with computer!hope you like it..


SOURCE
=======
import random       
import os
num=random.randint(1,50)
os.system('cls')
print '\tHOW TO'
print '\t','-'*6
print '\tIn this game I will think of a number from 1 to 50'
print '\tYOU HAVE SIX CHANCES TO GUESS THE NUMBER!'
print ''
print '\tGAME'
print '\t','-'*4
c=1
while c<=6:
    print '\tEnter your guess ',c,':'
    n=int(raw_input())
    if n>num:
        print '\tYour Guess is greater!'
    if n<num:
        print '\tYour Guess is smaller!'
    if n==num:
        break
    c=c+1
if n==num:
    print '\twow you have guessed it right! I thought of ',num
else:
    print '\tYou have finished all your six chances!'


#####################################################################
If you have any doubt ,contact me
run on python 2.7.12 interpreter
save as something.py
This is based on python 2.7 so,it will show error if you run it on python 3.5 interpreter..

OUTPUT
=======
================== RESTART: C:/Python27/guess.py ==================
HOW TO
------------
In this game I will think of a number from 1 to 50
YOU HAVE SIX CHANCES TO GUESS THE NUMBER!

GAME
---------
Enter your guess  1 :
25
Your Guess is smaller!
Enter your guess  2 :
40
Your Guess is greater!
Enter your guess  3 :
35
Your Guess is greater!
Enter your guess  4 :
30
Your Guess is greater!
Enter your guess  5 :
27
wow you have guessed it right! I thought of  27
#####################################################################
FEEL FREE TO ASK ME YOUR DOUBTS AND LEAVE COMMENTS!
#####################################################################