Python help

Joined
Sep 22, 2011
Messages
2
Reaction score
0
Hello,

I am new Python (about 2 weeks) and need some help. I am making a rock paper scissors game that a user can play with the computer by using a while loop and if elif else statements. It needs to keep score of the amount of losses and wins, and give the user the option to play again after each round. I've tried so many different options and I don't know what else to try. My problem is making the program loop back around when the user selects y(yes) to play again and defining the variables at the beginning. Here's my program:

import random
print"Welcome to Rock,Paper, Scissors! This is a game of chance; the computer randomly picks one of three throws."
print""
print"Rock beats Scissors, but is beaten by Paper."
print"Scissors beat Paper, but are beaten by Rock."
print"Paper beats Rock, but is beaten by Scissors."
print""
print"r for Rock"
print"s for Scissors"
wins=0
loses=0
print"p for Paper"
player=raw_input("Please pick your throw: (r,s,p):")
computer= random.choice(['r','s','p'])
print "Computer throw:", computer
y="something"
play=y
while play==y:
if player=='r':
if computer== 'r':
print "Tie! Throw again."
elif computer=='s':
print "You win! r beats s"
wins=wins+1
elif computer == 'p':
print "You lose! p beats r"
loses=loses+1
else:
pass
elif player=='s':
if computer== 's':
print "Tie! Throw again."
elif computer=='p':
print "You win! s beats p"
wins=wins+1
elif computer == 'r':
print "You lose! r beats s"
loses=loses+1
else:
pass
elif player=='p':
if computer== 'p':
print "Tie! Throw again."
elif computer=='r':
print "You win! p beats r"
wins=wins+1
elif computer == 's':
print "You lose! s beats p"
loses=loses+1
else:
pass
else:
print "Invalid entry"
print""
print"Game Summary"
print"Wins:", wins
print"Loses:",loses
play=raw_input("Play again? y (yes) or n (no):"
print"Thanks for playing!"



Thanks!

Joey
 
Joined
Sep 22, 2011
Messages
2
Reaction score
0
That doesn't look good. Attached is a print screen of my program. Thanks for your help!
 

Attachments

  • Program1 (1).jpg
    Program1 (1).jpg
    94.4 KB · Views: 319

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top