Python - Rock Paper Scissors Game

Discussion in 'Programming' started by MAD~DOG, Jan 9, 2010.

  1. #1
    import random
    import os
    c1 = 0
    a = ['1', '2', '3']
    p = random.choice(a)
    c2 = 0
    c3 = 0
    l = 1
    while l == 1:
        a = ['1', '2', '3']
        p = random.choice(a)
        os.system("clear")
        print "Your Options Are: "    
        print "1) Scissors"
        print "2) Paper"
        print "3) Rock"
        x = raw_input("Make Your Choice: ")
        if x == p:
            print "You Win!"
        if x != p:
            print "You Lose!"    
        raw_input("Press Enter To Continue")
        os.system("clear")
    Code (markup):

     
    MAD~DOG, Jan 9, 2010 IP
  2. Full Bird

    Full Bird Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Can you please explain the meaning of c1, c2 and c3 variables ?
     
    Full Bird, Jan 10, 2010 IP
  3. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #3
    This should work better.. (not tested since i don´t have python installed on any of my servers)
    
    import random
    import os
    while 1 == 1:
        a = ['1', '2', '3']
        p = random.choice(a)
        os.system("clear")
        print "Your Options Are: "    
        print "1) Scissors"
        print "2) Paper"
        print "3) Rock"
        print "4) Quit"
        x = raw_input("Make Your Choice: ")
        if x == 4:
            break;
        if p == 1:
            if x == 1:
                print "A Draw!"
            elif x == 2:
                print "You Lose!"
            elif x == 3:
                print "You Win!"
        elif p == 2:
            if x == 1:
                print "You Win!"
            elif x == 2:
                print "A Draw!"
            elif x == 3:
                print "You Lose!"
        elif p == 3:
            if x == 1:
                print "You Lose!"
            elif x == 2:
                print "You Win!"
            elif x == 3:
                print "A Draw!"
        raw_input("Press Enter To Continue")
        os.system("clear")
    
    PHP:
     
    n3r0x, Jan 11, 2010 IP