Rock, paper, scissors program


#1

i would really appreceate some help with the program i have tried to make, so far i have got reletively far but have only managed to get it to say what the user has put in along with the AI, i would like to add somthing that would compair the users answer with the computers and act accordingly, any help is appreceated, thanks

import random
options = ["Rock","Paper","Scissors"]
AI = random.choice(options)
user = input("Pick either Rock, Paper or Scissors ",)
user = user.lower()
if user == "rock":
print("The computer has drawn %s whilst you have drawn %s " % (AI,user))


#2

Is this what you are looking for?

import random

options = ["Rock","Paper","Scissors"]
AI = random.choice(options)
user = raw_input("Pick either Rock, Paper or Scissors: ")
user = user.lower()
if user == 'rock' or 'paper' or 'scissors':
    print "The computer has drawn %s whilst you have drawn %s " % (AI,user)
if user == 'rock':
    if AI == 'Rock':
        print 'Tie Game'
    elif AI == 'Paper':
        print 'AI Wins'
    else:
        print 'User Wins'
if user == 'paper':
    if AI == 'Rock':
        print 'User Wins'
    elif AI == 'Paper':
        print 'Tie Game'
    else:
        print 'AI Wins'
if user == 'scissors':
    if AI == 'Rock':
        print 'AI Wins'
    elif AI == 'Paper':
        print 'User Wins'
    else:
        print 'Tie Game'

#3

You don't really need all that code to get a rock paper scissors game,

Think about it like this

Rock = 1
Paper = 2
Scissors = 3

Rock - Rock = 0 # Draw
Rock - Paper = -1 # Lose
Rock - Scissors = -2 # Win

Paper - Rock = 1 # Win
Paper - Paper = 0 # Draw
Paper - Scissors = -1 # Lose

Scissors - Rock = 2 # Lose
Scissors - Paper = 1 # Win
Scissors - Scissors = 0 # Draw

As you can easily tell, 0 is always a draw, -1 is always a lose, -2 is a win, 1 is a win and finally 2 is a loss.

So all we have to do is handle the draw and win conditions and we shorten the code considerably.

First let's create a list of the items in the proper index order.

# You have to add one to the index number when computing scores
moves = ['Rock', 'Paper', 'Scissors']

Next let's create the if conditions

if movescore == 0:
    print("Tie!")
elif movescore in (1, -2):
    print("Win!")
else:
    print("You lose!")

Ok, now let's finish the last few parts.

ROCK PAPER SCISSORS CODE:

from random import randint

moves = ['Rock', 'Paper', 'Scissors']


def ask_move(player=False):
    if player:
        return moves.index(moves[int(raw_input("Pick a move, 1: %s, 2: %s, 3: %s"
                                           % (moves[0], moves[1], moves[2]))) - 1]) + 1
    else:
        return randint(1, 3)


def calculate_score(p1, p2):
    movescore = p1 -p2
    if movescore == 0:
        print("Tie!")
    elif movescore in (1, -2):
        print("Win!")
    else:
        print("You lose!")

if __name__ == "__main__":
    print("Welcome to the Rock, Paper, Scissors game!")
    while True:
        print("Player 1:\n")
        one = ask_move(True)
        two = ask_move()
        calculate_score(one, two)
        try:
            break_ = raw_input("Would you like to play again?\nEnter [1] if you would like to, else press enter.")
            if 1 == int(break_):
                print("Thank you for playing!")
            break
        except ValueError:
            print("Ok, here we go again\n")

Also here is a link to a Codeacademy Lab of this code.

As always best of luck.


#4

I have absolutely no idea where I am going wrong with this bit of code: I will follow the program frame with the error returned

"""unstrategically plays rock paper scissors
with a user and prints the outcome"""
from random import randint
from time import sleep

options = ["R","P","S"]

LOSER ="You are the RPS twat shot."
WINNER ="You just ring shot the cock block, son."

def decide_winner(user_choice, computer_choice):
print " You selected %s" % user_choice
print "Computer selecting..."
# sleep 1 second
print " Computer selected %s" % user_choice

user_choice_index = options.index(user_choice)
computer_choice_index = options.index(computer_choice)

if user_choice== computer_choice:
print "You may as well be a ■■■■■■■ robot."

elif user_choice == 0 and computer_choice == 2:
print

elif user_choice == 1 and computer_choice == 0:
print WINNER

elif user_choice == 2 and computer_choice == 1:
print WINNER

elif user_choice_index > 2:
print "selection invalid, asshole"
return
else :
print LOSER

def play_RPS():
print "Welcome to your secret ■■■■ hole of Devil's handshakes..."
user_choice = raw_input("Select R for Rock, P for Paper, or S for Scissors:")
user_choice = user_choice.upper()
computer_choice = options[randint(0,len(options)-1)]

decide_winner(user_choice, computer_choice)

play_RPS()

$ python RPS.py
File "RPS.py", line 40
user_choice = raw_input("Select R for Rock, P for Paper, or S for Scissors:")
^
IndentationError: unindent does not match any outer indentation level


#5