rock paper scissors.com code example

Example 1: rock paper scissors

import random

print('Get ready for rock,paper,scissors')
user = input('Enter your element:')
element = ['I choose Rock', 'I choose Paper', 'I choose Scissors']
AI = random.choice(element)
print(AI)
# Ties
if AI == str('I choose Rock') and user == str('rock'):
    print('Its a tie')
if AI == str('I choose Paper') and user == str('paper'):
    print('Its a tie')
if AI == str('I choose Scissors') and user == str('scissors'):
    print('Its a tie')
# Rock AI
if AI == str('I choose Rock') and user == str('paper'):
    print('You won')
if AI == str('I choose Rock') and user == str('scissors'):
    print('You lost')
# Rock user
if AI == str('I choose Paper') and user == str('rock'):
    print('You lost')
if AI == str('I choose Scissors') and user == str('rock'):
    print('You won')
# Paper AI
if AI == str('I choose Paper') and user == str('rock'):
    print('You lost')
if AI == str('I choose Paper') and user == str('scissors'):
    print('You won')
# Paper user
if AI == str('I choose Rock') and user == str('paper'):
    print('You won')
if AI == str('I choose Scissors') and user == str('paper'):
    print('You lost')
# Scissors AI
if AI == str('I choose Scissors') and user == str('paper'):
    print('You lost')
if AI == str('I choose Scissors') and user == str('rock'):
    print('You won')
# Scissors user
if AI == str('I choose Paper') and user == str('scissors'):
    print('You won')
if AI == str('I choose Rock') and user == str('scissors'):
    print('You lost')


def restartgame():
    print('Get ready for rock,paper,scissors')
    user = input('Enter your element:')
    element = ['I choose Rock', 'I choose Paper', 'I choose Scissors']
    AI = random.choice(element)
    print(AI)
    # Ties
    if AI == str('I choose Rock') and user == str('rock'):
        print('Its a tie')
    if AI == str('I choose Paper') and user == str('paper'):
        print('Its a tie')
    if AI == str('I choose Scissors') and user == str('scissors'):
        print('Its a tie')
    # Rock AI
    if AI == str('I choose Rock') and user == str('paper'):
        print('You won')
    if AI == str('I choose Rock') and user == str('scissors'):
        print('You lost')
    # Rock user
    if AI == str('I choose Paper') and user == str('rock'):
        print('You lost')
    if AI == str('I choose Scissors') and user == str('rock'):
        print('You won')
    # Paper AI
    if AI == str('I choose Paper') and user == str('rock'):
        print('You lost')
    if AI == str('I choose Paper') and user == str('scissors'):
        print('You won')
    # Paper user
    if AI == str('I choose Rock') and user == str('paper'):
        print('You won')
    if AI == str('I choose Scissors') and user == str('paper'):
        print('You lost')
    # Scissors AI
    if AI == str('I choose Scissors') and user == str('paper'):
        print('You lost')
    if AI == str('I choose Scissors') and user == str('rock'):
        print('You won')
    # Scissors user
    if AI == str('I choose Paper') and user == str('scissors'):
        print('You won')
    if AI == str('I choose Rock') and user == str('scissors'):
        print('You lost')
    again = input('Would you like to play again')
    if again == str('yes'):
        restartgame()
    if again == str('no'):
        raise SystemExit(0)


again = input('Would you like to play again')
if again == str('yes'):
    restartgame()
if again == str('no'):
    raise SystemExit(0)

Example 2: rock paper scissors java

import java.util.Scanner;
import java.util.Random;

public class rps {
    public static void main (String args[]){
        int input;
        int b = 1;
        Scanner sage = new Scanner(System.in);
        Random rnd = new Random();
    System.out.println("Rock Paper Scissors, by Sage!");
    System.out.println("Select 1, 2, 3, for Rock, Paper, Scissors");
    //Menu Present, pretty bad still

        while (b != 0){
        int rock = 1, paper = 2, scissors = 3;
        input = sage.nextInt();
        int randomNumber = rnd.nextInt(3-1+1)+1;

            if(randomNumber == rock){
                if(input == rock){
                    System.out.println("Rock vs. Rock, ITS A TIE!");
            }    else if(input == paper){
                    System.out.println("Rock vs. Paper! You win!" );
            }    else if(input == scissors){
                    System.out.println("Rock vs. Scissors! You lose!");
            }  //These blocks establish options if the computer got Rock

            else if(randomNumber == paper){
                if(input == rock){
                    System.out.println("Paper vs. Rock! You lose!");
            }   else if(input == scissors){
                    System.out.println("Paper vs. Scissors! You win!");
            }   else if(input == paper){
                    System.out.println("Paper vs. Paper! Its a tie!");
            } //These blocks establish the options if comp. got paper

            else if(randomNumber == scissors){
                if(input == rock){
                    System.out.println("Scissors vs. Rock! You win!");
            }   else if(input == scissors){
                    System.out.println("Scissors vs. Scissors, ITS A TIE!");
            }   else if(input == paper){
                    System.out.println("Scissors vs Paper! You lose!");
            } //These blocks establish if the computer got scissors.

            }
            }
            rps2 rps2Object = new rps2();
            rps2Object.rps2();


        }

    }
    }
}

Tags:

Java Example