<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 9/23/2011 2:04 PM, Joseph Shakespeare wrote:
<blockquote
cite="mid:CAB=+OuSjUCCjQ3FHN1aK2F3B-iVrPLg24xAmAPYS-0DSqjpSjA@mail.gmail.com"
type="cite">Wow, thanks so much! This is amazing!
<div>One question though. I understand everything in the program
except these 2 lines:</div>
<div>
<div><br>
</div>
<div>Wins: %s</div>
<div>Loses:%s""" % (wins,loses)</div>
<div>
<br>
</div>
<div>There are 2 things I don't understand.</div>
<div>1. the %s</div>
<div>2. the (wins,loses)</div>
<div><br>
</div>
<div>Any explanation you have would be helpful.</div>
<div>Thanks for taking the time to help the newbie!</div>
<div><br>
</div>
<div>Joey</div>
<div><br>
</div>
<div><br>
</div>
<br>
<div class="gmail_quote">On Thu, Sep 22, 2011 at 6:35 PM, bob
gailer <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:bgailer@gmail.com">bgailer@gmail.com</a>></span>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex;">On
9/22/2011 1:04 PM, Joseph Shakespeare wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
</blockquote>
<br>
Hi - please use a meaningful subject line - I've changed it
this time<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
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:<br>
<br>
</blockquote>
I've taken the liberty to extensively edit (and simplify)
your program. Cut 60 lines to 34. Study it - there are a lot
of useful ideas in it. Feel free to ask questions.<br>
<br>
The following 3 llnes will NOT get you what you want. You
appear to be confusing variable names with strings.<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
y="something"<br>
play=y<br>
while play==y:<br>
</blockquote>
<br>
The while condition is not true - the program will not run.<br>
<br>
The proper initialization is:<br>
<br>
play = "y"<br>
<br>
However I've eliminated the need for even that.<br>
<br>
import random<br>
# Use a triple-quoted string rather than a bunch of print
statements.<br>
print """Welcome to Rock,Paper, Scissors! This is a game of
chance.<br>
The computer randomly picks one of three throws.<br>
Rock beats Scissors, but is beaten by Paper.<br>
Scissors beat Paper, but are beaten by Rock.<br>
Paper beats Rock, but is beaten by Scissors.<br>
You enter:<br>
r for Rock<br>
s for Scissors<br>
p for Paper<br>
q to Quit'"""<br>
wins = loses = 0<br>
while True: # "endless" loop - exited by break statement<br>
player = raw_input("Please pick your throw: (r, s, p, or
q ):")<br>
if player == "q":<br>
break # exits the loop<br>
elif player not in "rps": # check for valid entry<br>
print "Invalid entry"<br>
else:<br>
computer= random.choice("rsp") # no need for a list -
a string is a sequence<br>
print "Computer throw:", computer<br>
if player == computer: # testing various conditiions
cam be greatly simplified<br>
print "Tie! Throw again."<br>
elif player + computer in ["rs", "sp", "pr"]:<br>
print "You win! " + player + " beats " + computer<br>
wins += 1 # simpler than wins = wins + 1<br>
else:<br>
print "You lose! " + computer + " beats " +
player<br>
loses +=1<br>
print """Game Summary<br>
Wins: %s<br>
Loses:" %s""" % (wins,loses) # using % formatting and triple
quoted string<br>
print"Thanks for playing!"<br>
<font color="#888888">
<br>
<br>
-- Bob Gailer <a moz-do-not-send="true"
href="tel:919-636-4239" value="+19196364239"
target="_blank">919-636-4239</a> Chapel Hill NC<br>
</font></blockquote>
</div>
<br>
</div>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Bob Gailer
919-636-4239
Chapel Hill NC</pre>
</body>
</html>