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
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor