Im writing a game of scissors paper rock and have come up with this so far, but i cant get it to work.
any idea's where ive gone wrong.

print \
'''
a - Rock
b - Paper
c - Scissors
'''
choice1 = raw_input("Choice: ")
print

if choice1 == 'a':
print 'You picked rock'
elif choice1 == 'b':
print 'You picked paper'
elif choice1 == 'c':
print 'You picked scissors'

computer = random.randrange(3)
if computer == 0:
print 'Computer rolled Rock'
elif computer == 1:
print 'Computer picked Paper'
elif computer == 2:
print 'Computer picked Scissors'

if player.upper() == 'a' and ai.upper() == 'c':
win += 1
print 'Rock crushes scissors...You WIN this round!'
elif player.upper() == 'c' and ai.upper() == 'b':
win += 1
print 'Scissors cuts paper... You wIN this round!'
elif player.upper() == 'b' and ai.upper() == 'a':
win += 1
print 'Paper wraps up that rock...You wIN this round!'
else:
lose += 1
print 'YOU LOSE!!!'

win = 0
lose = 0
tie = 0

scores = {"player1":0, "computer":0}
if player1 won:
scores["player1"] += 1
elif computer won:
scores["computer"]+= 1

while scores > = 10:
print player, "Wins"


I cant get it to run past the enter your choice of a b or c for some reason.

Recommended Answers

All 3 Replies

(1) Use the [code="Python"] and
[/code]
tags to format your code correctly.

(2) WRT your code, walk through line-by-line.

print \
'''
a - Rock
b - Paper
c - Scissors
'''
choice1 = raw_input("Choice: ")
print
  
if choice1 == 'a':
    print 'You picked rock'
elif choice1 == 'b':
    print 'You picked paper'
elif choice1 == 'c':
    print 'You picked scissors'

computer = random.randrange(3)
if computer == 0:
    print 'Computer rolled Rock'
elif computer == 1:
    print 'Computer picked Paper'
elif computer == 2:
    print 'Computer picked Scissors'

if player.upper() == 'a' and ai.upper() == 'c':
    win += 1
    print 'Rock crushes scissors...You WIN this round!'
elif player.upper() == 'c' and ai.upper() == 'b':
    win += 1
    print 'Scissors cuts paper... You wIN this round!'
elif player.upper() == 'b' and ai.upper() == 'a':
    win += 1
    print 'Paper wraps up that rock...You wIN this round!'
else:
    lose += 1
    print 'YOU LOSE!!!'

win = 0
lose = 0
tie = 0

scores = {"player1":0, "computer":0}
if player1 won:
     scores["player1"] += 1
elif computer won:
     scores["computer"]+= 1

while scores > = 10:
    print player, "Wins"

Notice that lines 1-37 only get executed once, EVER. Thus, you only play one game! And then, because scores is a dictionary, it is never larger than 10 (that's confusing -- basically, you're comparing apples and oranges in line 48), the while loop never executes.

So what you need is the same basic code, but restructured so that the user plays the game ten times.

Hope it helps,
Jeff

I've rearranged without much luck...I still cant see what im doing wrong...

print \
      '''
      a - Rock
      b - Paper
      c - Scissors
      '''

choice1 = raw_input("Choice: ")
print

if choice1 == 'a':
    print 'You picked rock'
elif choice1 == 'b':
    print 'You picked paper'
elif choice1 == 'c':
    print 'You picked scissors'

computer = random.randrange(3)
if computer == 0:
    print 'Computer rolled Rock'
elif computer == 1:
    print 'Computer picked Paper'
elif computer == 2:
    print 'Computer picked Scissors'

if player1 == 'a' and computer == 'c':
    win += 1
    print 'Rock crushes scissors...You WIN this round!'
elif player1 == 'c' and computer == 'b':
    win += 1
    print 'Scissors cuts paper... You wIN this round!'
elif player1 == 'b' and computer == 'a':
    win += 1
    print 'Paper wraps up that rock...You wIN this round!'
elif computer == 'a' and player1 =='c':
    win += 1
    print 'Rock crushes scissors...You WIN this round!'
elif computer == 'c' and player1 == 'b':
    win += 1
    print 'Scissors cuts paper... You wIN this round!'
elif computer == 'b' and player1 == 'a':
    win += 1
    print 'Paper wraps up that rock...You wIN this round!'
elif player == 'a' and computer == 'a':
    tie += 0
    print 'You both chose the same, try again.'
elif player1 == 'b' and computer == 'b':
    tie += 0
    print 'You both chose the same option, try again. '
elif player1 == 'c' and computer == 'c':
    tie += 0
    print 'You both chose the same option, try again. '
else:
    lose += 1
    print 'YOU LOSE!!!'

while score > = 10
    if player1 or computer score < = 10:
        print 'Your score is ', score
    else:
        choice1 = raw_input("Choice: ")
        print

score = {'player1': 0, 'computer': 0}
if player1 won:
    score=['player1'] += 1
elif computer won:
    score["computer"] += 1

raw_input('\nPress Enter to exit.')

You could write it something like this, where the game is in a function that gets called from the loop:

# Rock, Paper, Scissors game

import random

def game(win, lose, tie):
    print \
    '''
    a - Rock
    b - Paper
    c - Scissors
    '''
    player = raw_input("Choice (a, b or c): ").lower()
    print
      
    if player == 'a':
        print 'You picked rock'
    elif player == 'b':
        print 'You picked paper'
    elif player == 'c':
        print 'You picked scissors'

    computer = random.choice(['a', 'b', 'c'])
    if computer == 'a':
        print 'Computer picked Rock'
    elif computer == 'b':
        print 'Computer picked Paper'
    elif computer == 'c':
        print 'Computer picked Scissors'

    if player == 'a' and computer == 'c':
        win += 1
        print 'Rock crushes scissors...You WIN this round!'
    elif player == 'c' and computer == 'b':
        win += 1
        print 'Scissors cuts paper... You wIN this round!'
    elif player == 'b' and computer == 'a':
        win += 1
        print 'Paper wraps up that rock...You wIN this round!'
    elif player == computer:
        tie += 1
        print "It's a tie!"
    else:
        lose += 1
        print 'YOU LOSE!!!'
    return win, lose, tie


win = 0
lose = 0
tie = 0

games = 0
while True:
    win, lose, tie = game(win, lose, tie)
    games += 1
    print "Games =", games
    print "Wins =", win,   "Loses =", lose,   "Ties =", tie
    # stop after 10 games
    if games >= 10:
        break

raw_input("Thank you for playing!  Press enter ... ")
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.