[Tutor] Help!

bob gailer bgailer at gmail.com
Fri Oct 7 22:28:38 CEST 2011

On 10/7/2011 12:32 PM, rmntcverses at aol.com wrote:
> I need serious help with this Rock, Paper, Scissors program. The 
> program runs smoothly but I can't get the score to print. Please help 
> me with this one aspect! Here is my code right now:

Welcome to Python Help.

In future please use a meaningful subject, such as 'Rock Paper Scissors"

Always reply-all so a copy goes to the list.

We had a similar discussion recently on the Python-Tutor list. I 
submitted an alternate version of the game, which I reproduce here for 
your perusal. It uses some features of Python which may be new to you. 
Please study it, as it may offer some learning.

import random
print """Welcome to Rock,Paper, Scissors! This is a game of chance.
The computer randomly picks one of three throws.
Rock beats Scissors, but is beaten by Paper.
Scissors beat Paper, but are beaten by Rock.
Paper beats Rock, but is beaten by Scissors.
You enter:
r for Rock
s for Scissors
p for Paper
q to Quit'"""
wins = loses = 0
while True: # "endless" loop - exited by break statement
     player = raw_input("Please pick your throw: (r, s, p, or q ):")
     if player == "q":
         break # exits the loop
     elif player not in "rps": # check for valid entry
         print "Invalid entry"
         computer= random.choice("rsp") # no need for a list - a string 
is a sequence
         print "Computer throw:", computer
         if player == computer: # testing various conditiions cam be 
greatly simplified
             print "Tie! Throw again."
         elif player + computer in ["rs", "sp", "pr"]:
             print "You win! " + player + " beats " + computer
             wins += 1 # simpler than wins = wins + 1
             print "You lose! " + computer + " beats " + player
             loses +=1
         print """Game Summary
Wins: %s
Loses:" %s""" % (wins,loses) # using % formatting and triple quoted string
print"Thanks for playing!"

-- Bob Gailer
Chapel Hill NC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111007/9d82ae7c/attachment.html>

More information about the Tutor mailing list