jeudi 27 août 2015

Simple rock, paper, scissors game [Python]

I'm trying to write a simple RPS game but I'm having trouble getting the program to display the result of the game. Mind you, I'm a total beginner in programming and I've written all this from what I've learned previously so it probably isn't the most efficent way to write a game like this.

import random
rps = ['rock', 'paper', 'scissors']
rps2 = (random.choice(rps))

print 'Welcome to RPS'
print 'Press 1 to pick Rock'
print 'Press 2 to pick Paper'
print 'Press 3 to pick Scissors'
print 'Press 4 to quit.'


while True:
    game = int(raw_input('What do you pick? '))
    if game == 1:
        print 'You picked rock.'
        print 'The computer picked...' + (random.choice(rps))
        if rps2 == [0]:
            print 'It\'s a tie!'
        elif rps2 == [1]:
            print 'You lose!'
        elif rps2 == [2]:
            print 'You win!'
    elif game == 2:
        print 'You picked paper.'
        print 'The computer picked...' + (random.choice(rps))
        if rps2 == [0]:
            print 'You win!'
        elif rps2 == [1]:
            print 'It\'s a tie!'
        elif rps2 == [2]:
            print 'You lose!'
    elif game == 3:
        print 'You picked scissors.'
        print 'The computer picked...' + (random.choice(rps))
    if rps2 == [0]:
        print 'You lose!'
    elif rps2 == [1]:
        print 'You win!'
    elif rps2 == [2]:
        print 'It\'s a tie!'
    elif game == 4:
        print 'Thank you for playing!'
        break
    else:
        continue

Aucun commentaire:

Enregistrer un commentaire