Friday, 30 September 2016

Game of Rock Paper Scissors in Python

Rock Paper Scissors (Python)

import random
lst = ['rock','paper','scissors']
print "\n\n Rock, Paper and Scissors \n\n"
print "\n You are playing vs Computer\n"
user = raw_input("Enter yr name:")
while(True):

    user1 = raw_input("%s, do yo want to choose rock, paper or scissors?" % user)

    if user1 not in lst:
        print "Invalid Input(Please input exaclty words givne to choose)"
    computer = random.choice(lst)
    if user1 in lst:
        print 'Computer chooses', computer
    if computer == user1:
        print 'Its a Tie'
    if computer == 'rock' and user1 == 'paper':
        print '\n\n%s Wins\n\n' %user
    if computer == 'rock' and user1 == 'scissors':
        print '\n\nComputer Wins\n\n'
    if computer == 'paper' and user1 == 'rock':
        print '\n\nComputer Wins\n\n'
    if computer == 'paper' and user1 == 'scissors':
        print '\n\n%s Wins\n\n' %user
    if computer == 'scissors' and user1 == 'rock':
        print '\n\n%s Wins\n\n' %user
    if computer == 'scissors' and user1 == 'paper':
        print '\n\nComputer Wins\n\n'
    print 'Play again(yes/no)'
    user_play_again = raw_input('\nEnter(yes or no):\n')
    if user_play_again == 'yes':
        continue
    else:
         print '\n\nGame Over\n\n'

         break



OUTPUT:


Game of Rock Paper Scissors

No comments:

Post a Comment