why are printing the string using three quotes? I know three means a doc string... just not sure. <div><br></div><div><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
if guess_iflow == random_num:</p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "> print """That was right! I guess you're smarter than me...</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "> even though it took you another try!"""</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
Ok you said this program is for children. I think the flow of ifs and elifs might be a little complex for a child.</p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">Why not set it up like this for a first try for a child programmer?</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
Generate random number</p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">Ask for a guess</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">if guess is too high say "to high"</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">if guess is too low say "to low"</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">if guess equeals the random number "you got it, exit"</p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">repeat</p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<br></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">You can eliminate that whole second flow if you just have it repeat the process each time with a new guess input from the child. </span></font></p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br>
</span></font></p><p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">This also enables you to guess an unlimited amount of times at the answer each time comming closer and closer. Its kind of a cool game for a first try. </span></font></p>
<p class="MsoNormal" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "> </p><br><div class="gmail_quote">On Sat, Mar 5, 2011 at 6:38 PM, Julie Bell <span dir="ltr"><<a href="mailto:jmwebstuff@yahoo.com">jmwebstuff@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><table cellspacing="0" cellpadding="0" border="0"><tbody><tr><td valign="top" style="font:inherit">I am not a true python programmer. But I'd put the repeating messages into a subroutine.<br>
1. To save on code space<br>2. To be able to change message in one place<br>3. Easier Readability of program<br><br>The other thing I would do is put it into a loop the tries.<br><br><br> #simple number guessing game<br>
<br>import random<br><br>def correct():<div class="im"><br> print "You got it! I guess you are smarter than me!"<br></div> return<br><br>def correct2():<div class="im"><br> print """That was right! I guess you're smarter than me...<br>
even though it took you another try!"""<br></div> return<br><br>def wrong(random_num):<div class="im"><br><br> print "Nope! I'm smarter than
you!"<br> print "I was thinking of the number: ", random_num<br></div> return <br><div class="im"><br>def main():<br><br> print "Do you think you're smarter than me?"<br> print "I guess we'll see!"<br>
print "I'm thinking of a number between 0 - 100. Can you guess what it is?"<br> print<br><br><br> guess = input("Type a number between 0 - 100: ")<br> random_num = random.randrange(0,100,1)<br>
<br> if guess == random_num:<br></div> correct()<div class="im"><br> <br> elif guess < random_num:<br><br> # user gets second chance if number is too low<br> guess_iflow = input("You were too low. Type another number:
")<br><br> if guess_iflow == random_num:<br></div> correct2()<br> else:<br> wrong(random_num)<div class="im"><br><br> elif guess > random_num:<br><br> # user gets second chance if number is too high<br>
guess_ifhigh = input("You were too high. Type another number: ")<br><br> if guess_ifhigh == random_num:<br></div> correct2()<br> else:<br> wrong(random_num)<br> else:<br>
wrong(random_num)<br><br>main()<br><br><br>--- On <b>Sat, 3/5/11, kirby urner <i><<a href="mailto:kirby.urner@gmail.com" target="_blank">kirby.urner@gmail.com</a>></i></b> wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px">
<br>From: kirby urner <<a href="mailto:kirby.urner@gmail.com" target="_blank">kirby.urner@gmail.com</a>><br>Subject: Re: [Chicago] How could I make this better?<br>To: "The Chicago Python Users Group" <<a href="mailto:chicago@python.org" target="_blank">chicago@python.org</a>><br>
Date: Saturday, March 5, 2011, 5:28 PM<div><div></div><div class="h5"><br><br><div>Is you goal to share the source code with your kids?<div><br></div><div>Dunno how young, but you might wanna make the if / elif / else stuff less deep. Just ifs, without elifs or elses might be cool.</div>
<div><br></div><div>
I'd probably make it a while True loop (with break conditions). A blank guess might mean "I give up" (nice to have an escape route).</div><div><br></div><div>Chances of guessing the number in one or two guesses is about nil.</div>
<div><br></div><div>I'd think the proposer of this puzzle wan't very smart if I had to play such a game. :)</div><div><br></div><div>Note that in Python 3, input returns a string, not an integer (so convert -- but you can catch a blank first, as distinct from 0).</div>
<div><br></div><div>If your goal is to teach Python to your kids, I'd recommend Python 3.</div><div><br></div><div>Kirby</div><div><br><div>On Sat, Mar 5, 2011 at 4:34 PM, Malcolm Newsome <span dir="ltr"><<a rel="nofollow" href="http://mc/compose?to=malcolm.newsome@gmail.com" target="_blank">malcolm.newsome@gmail.com</a>></span> wrote:<br>
<blockquote style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex"><div lang="EN-US"><div><p>Hey all. I wrote this simple program for my children today. I’m wondering if there was a more efficient alternative to the way I wrote it.</p>
<p> </p><p> </p><p> </p><p># guess.py</p><p># a simple number guessing game</p><p> </p><p>import random</p>
<p> </p><p>def main():</p><p> </p><p> print "Do you think you're smarter than me?"</p><p> print "I guess we'll see!"</p>
<p> print "I'm thinking of a number between 0 - 100. Can you guess what it is?"</p><p> print</p><p> </p><p> guess = input("Type a number between 0 - 100: ")</p>
<p> </p><p> random_num = random.randrange(0,100,1)</p><p> </p><p> if guess == random_num:</p><p> print "You got it! I guess you are smarter than me!"</p>
<p> </p><p> elif guess < random_num:</p><p> # user gets second chance if number is too low</p><p> guess_iflow = input("You were too low. Type another number: ")</p>
<p> </p><p> if guess_iflow == random_num:</p><p> print """That was right! I guess you're smarter than me...</p><p>
even though it took you another try!"""</p><p> </p><p> else:</p><p> print "Nope! I'm smarter than you!"</p>
<p> print "I was thinking of the number: ", random_num</p><p> </p><p> elif guess > random_num:</p><p> # user gets second chance if number is too high</p>
<p> guess_ifhigh = input("You were too high. Type another number: ")</p><p> </p><p> if guess_ifhigh == random_num:</p><p>
print """That was right! I guess you're smarter than me...</p><p> even though it took you another try!"""</p><p> </p><p>
else:</p><p> print "Nope! I'm smarter than you!"</p><p> print "I was thinking of the number: ", random_num</p><p>
</p><p> else:</p><p> print "Nope! I'm smarter than you!"</p><p> print "I was thinking of the number: ", random_num</p><p>
</p><p>main()</p><p> </p></div></div><br>_______________________________________________<br>
Chicago mailing list<br>
<a rel="nofollow" href="http://mc/compose?to=Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a rel="nofollow" href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div>
</div><br></div></div>-----Inline Attachment Follows-----<div class="im"><br><br><div>_______________________________________________<br>Chicago mailing list<br><a href="http://mc/compose?to=Chicago@python.org" target="_blank">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br></div></div></blockquote></td></tr></tbody></table><br>
<br>_______________________________________________<br>
Chicago mailing list<br>
<a href="mailto:Chicago@python.org">Chicago@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/chicago" target="_blank">http://mail.python.org/mailman/listinfo/chicago</a><br>
<br></blockquote></div><br></div>