Stone, Paper and Scissors game | Python Program

Stone, Paper and Scissors game:

 Tips:

    1."import random" from library file.
    2.Use nested if and else
    3.You should know stone, paper and scissor game.


Code:

import random
print("Hello!!\nPlay Rock! Paper! Scissor!\nUser v/s Computer.")
print('Who ever wins 5 times first becomes the winner of the game.')
player_count=0
comp_count=0
while(True):
    if player_count>=5 or comp_count>=5:
        break;
    x=random.choice(['rock','paper','scissor'])
    print("\nComp = "+str(comp_count)+" |  You = "+str(player_count)+"\nEnter your choice:",end=' ')
    n=input()
    if(n!=x):
        print("\ncomputer choose:",x)
        print("you choose:",n,"\n")
        if(x=='rock' and n=='paper'):
            print("you win!")
            player_count=player_count+1
        elif(x=='paper' and n=='scissor'):
            print("you win!")
            player_count=player_count+1
        elif(x=='scissor' and n=='rock'):
            print("you win!")
            player_count=player_count+1
        elif(x=='rock' and n=='scissor'):
            print("computer win!")
            comp_count=comp_count+1
        elif(x=='paper' and n=='rock'):
            print("computer win!")
            comp_count=comp_count+1
        elif(x=='scissor' and n=='paper'):
            print("computer win!")
            comp_count=comp_count+1
    else:
        print("\nDraw!\n")
        print("computer choose:",x)
        print("you choose:",n)           
print("\nComp = "+str(comp_count)+" |  You = "+str(player_count))
if player_count==5:
    print('\nYou are the winner of this game !!!!')
else:
    print('\nSorry, computer is the winner of this game.\nBetter luck next time.')

Output:



 

Comment!

Comments

Popular posts from this blog

Print name in a pattern | name as abbreviation | C-Program

C program of Cyclic Redundancy Check