Results 1 to 5 of 5
  1. #1
    Poloh's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    67
    Reputation
    10
    Thanks
    16

    Rock Paper Scissors Source Code

    #poloh
    import random

    userHand = input("rock, paper, or scissors")
    computerHand = random.random()

    if computerHand < .33:
    computerHand = ("rock")
    elif computerHand < .66:
    computerHand = ("paper")
    else:
    computerHand = ("scissors")


    def game(first,second):
    if first == second:
    print ("You chose",first)
    print ("Computer chose", second)
    print ("It's a tie!")
    elif first == ("rock"):
    if second == ("scissors"):
    print ("You chose",first)
    print ("Computer chose",second)
    print ("You Win!")
    else:
    print ("You chose", first)
    print ("Comuter chose", second)
    print ("You lose.")
    elif first == ("paper"):
    if second == ("rock"):
    print ("You chose",first)
    print ("Computer chose",second)
    print ("You Win!")
    else:
    print ("You chose", first)
    print ("Comuter chose", second)
    print ("You lose.")
    elif first == ("scissors"):
    if second == ("paper"):
    print ("You chose",first)
    print ("Computer chose",second)
    print ("You Win!")
    else:
    print ("You chose", first)
    print ("Comuter chose", second)
    print ("You lose.")

    game(userHand,computerHand)

  2. #2
    K4LI's Avatar
    Join Date
    Apr 2016
    Gender
    male
    Posts
    403
    Reputation
    90
    Thanks
    74
    My Mood
    Fine
    Quote Originally Posted by Poloh View Post
    #poloh
    import random

    userHand = input("rock, paper, or scissors")
    computerHand = random.random()

    if computerHand < .33:
    computerHand = ("rock")
    elif computerHand < .66:
    computerHand = ("paper")
    else:
    computerHand = ("scissors")


    def game(first,second):
    if first == second:
    print ("You chose",first)
    print ("Computer chose", second)
    print ("It's a tie!")
    elif first == ("rock"):
    if second == ("scissors"):
    print ("You chose",first)
    print ("Computer chose",second)
    print ("You Win!")
    else:
    print ("You chose", first)
    print ("Comuter chose", second)
    print ("You lose.")
    elif first == ("paper"):
    if second == ("rock"):
    print ("You chose",first)
    print ("Computer chose",second)
    print ("You Win!")
    else:
    print ("You chose", first)
    print ("Comuter chose", second)
    print ("You lose.")
    elif first == ("scissors"):
    if second == ("paper"):
    print ("You chose",first)
    print ("Computer chose",second)
    print ("You Win!")
    else:
    print ("You chose", first)
    print ("Comuter chose", second)
    print ("You lose.")

    game(userHand,computerHand)
    Put this inside the "CODE" tag in order to make it readable, moreover there is NO INDENTATION which is too bad in Python lol

  3. The Following 2 Users Say Thank You to K4LI For This Useful Post:

    heydude2 (12-31-2016),Poloh (12-26-2016)

  4. #3
    Poloh's Avatar
    Join Date
    Aug 2016
    Gender
    male
    Posts
    67
    Reputation
    10
    Thanks
    16
    Quote Originally Posted by K4LI View Post
    Put this inside the "CODE" tag in order to make it readable, moreover there is NO INDENTATION which is too bad in Python lol
    I was looking for that CODE function haha thanks!

  5. #4
    ASERHaerheadrherherh's Avatar
    Join Date
    Mar 2014
    Gender
    male
    Location
    California
    Posts
    716
    Reputation
    23
    Thanks
    93
    My Mood
    Angelic
    Code:
    #poloh
    import random
    
    userHand = input("rock, paper, or scissors")
    computerHand = random.random()
    
    if computerHand < .33:
        computerHand = ("rock")
    elif computerHand < .66:
        computerHand = ("paper")
    else:
        computerHand = ("scissors")
    
    
    def game(first,second):
        if first == second:
            print ("You chose",first)
            print ("Computer chose", second)
            print ("It's a tie!")
        elif first == ("rock"):
            if second == ("scissors"):
                print ("You chose",first)
                print ("Computer chose",second)
                print ("You Win!")
            else:
                print ("You chose", first)
                print ("Comuter chose", second)
                print ("You lose.")
        elif first == ("paper"):
            if second == ("rock"):
                print ("You chose",first)
                print ("Computer chose",second)
                print ("You Win!")
            else:
                print ("You chose", first)
                print ("Comuter chose", second)
                print ("You lose.")
        elif first == ("scissors"):
            if second == ("paper"):
                print ("You chose",first)
                print ("Computer chose",second)
                print ("You Win!")
        else:
            print ("You chose", first)
            print ("Comuter chose", second)
            print ("You lose.")
    game(userHand,computerHand)
    Indented for easier reading.

    Also, if you want to print on a new line, instead of doing three print statements, there should be some way to use a newline to put it all into one statement, idk how though.

  6. #5
    Nimboso's Avatar
    Join Date
    Sep 2015
    Gender
    male
    Posts
    554
    Reputation
    21
    Thanks
    2,635
    Plus, since you're printing the users choice, and computers choice every time, you can print it above the if statements to remove a lot of repetition from your code.

    Code:
    print("You chose", first, "\nComputer chose", second)
    if you care about using the newline over multiple print statements.
    Last edited by Nimboso; 01-11-2017 at 07:48 PM.

Similar Threads

  1. [Help Request] Rock, Paper, Scissor game. Random number generator not working.
    By samlarenskoog in forum C++/C Programming
    Replies: 6
    Last Post: 04-19-2016, 04:22 AM
  2. [Source Code] Lock Mode V.2 & Paper/FatA*** Hack [ Source Code ]
    By Aeir in forum Piercing Blow Hack Coding/Source Code
    Replies: 1
    Last Post: 01-25-2012, 04:38 PM
  3. Rock paper scissor lizard spock
    By Woods in forum General
    Replies: 2
    Last Post: 10-27-2011, 07:05 PM
  4. [Release]Scissors, rock, paper
    By /b/oss in forum Visual Basic Programming
    Replies: 21
    Last Post: 05-19-2010, 06:19 PM
  5. rock, paper, scissors
    By ace76543 in forum General
    Replies: 5
    Last Post: 12-01-2007, 04:31 PM