<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">mai date&nbsp; in pula&nbsp; mea&nbsp; cu masurile&nbsp; tale&nbsp; mai acrit&nbsp; la coie&nbsp; mai termina&nbsp; in plm cu&nbsp; ele<br><br>--- On <b>Sun, 10/24/10, tutor-request@python.org <i>&lt;tutor-request@python.org&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: tutor-request@python.org &lt;tutor-request@python.org&gt;<br>Subject: Tutor Digest, Vol 80, Issue 108<br>To: tutor@python.org<br>Date: Sunday, October 24, 2010, 12:25 PM<br><br><div class="plainMail">Send Tutor mailing list submissions to<br>&nbsp;&nbsp;&nbsp; <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br><br>To subscribe or unsubscribe via the World Wide Web, visit<br>&nbsp;&nbsp;&nbsp; <a href="http://mail.python.org/mailman/listinfo/tutor"
 target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>or, via email, send a message with subject or body 'help' to<br>&nbsp;&nbsp;&nbsp; <a ymailto="mailto:tutor-request@python.org" href="/mc/compose?to=tutor-request@python.org">tutor-request@python.org</a><br><br>You can reach the person managing the list at<br>&nbsp;&nbsp;&nbsp; <a ymailto="mailto:tutor-owner@python.org" href="/mc/compose?to=tutor-owner@python.org">tutor-owner@python.org</a><br><br>When replying, please edit your Subject line so it is more specific<br>than "Re: Contents of Tutor digest..."<br><br><br>Today's Topics:<br><br>&nbsp;&nbsp;&nbsp;1. Re: Scripting-Puzzle Pirates (Lie Ryan)<br>&nbsp;&nbsp;&nbsp;2. What's the best way to model an unfair coin? (Richard D. Moores)<br>&nbsp;&nbsp;&nbsp;3. Re: What's the best way to model an unfair coin? (Evert Rol)<br>&nbsp;&nbsp;&nbsp;4. Re: What does "TypeError: 'int' object is not iterable"&nbsp;&nbsp;&nbsp; mean?<br>&nbsp;
 &nbsp; &nbsp; (Richard D. Moores)<br>&nbsp;&nbsp;&nbsp;5. Re: What's the best way to model an unfair coin? (Steven D'Aprano)<br>&nbsp;&nbsp;&nbsp;6. Re: What's the best way to model an unfair coin? (Alan Gauld)<br>&nbsp;&nbsp;&nbsp;7. Re: What's the best way to model an unfair coin? (Evert Rol)<br><br><br>----------------------------------------------------------------------<br><br>Message: 1<br>Date: Sun, 24 Oct 2010 21:05:30 +1100<br>From: Lie Ryan &lt;<a ymailto="mailto:lie.1296@gmail.com" href="/mc/compose?to=lie.1296@gmail.com">lie.1296@gmail.com</a>&gt;<br>To: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>Subject: Re: [Tutor] Scripting-Puzzle Pirates<br>Message-ID: &lt;ia13ff$t9m$<a ymailto="mailto:1@dough.gmane.org" href="/mc/compose?to=1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>Content-Type: text/plain; charset=ISO-8859-1<br><br>On 10/24/10 15:33, Nathan Finney wrote:<br>&gt;
 Hey,<br>&gt;&nbsp; <br>&gt; So I got bored of having to do a repeated task on this game, YPP Puzzle<br>&gt; Pirates and I was wondering if it was possible to script it. <br><br>Even if you can (hint: no, you can't), most games consider writing<br>scripts to do tasks as botting, i.e. cheating.<br><br>&gt; My task<br>&gt; would be to start at a dock, click on the port arrow, choose a ship (a<br>&gt; different one each time and in order preferably), go to its hold, select<br>&gt; materials to be moved and move them to a set ship (the same one each<br>&gt; time), then return to the starting position.<br><br>Now, that would be stealing or just rude, even if you do it manually.<br><br>&gt; If this is possible would I first need a set of the games coding (which<br>&gt; uses javascript) to be obtained so it could be read and a script used<br>&gt; upon it.<br><br>Java is not the same as Javascript. Puzzle Pirate is a Java
 game.<br><br><br><br>------------------------------<br><br>Message: 2<br>Date: Sun, 24 Oct 2010 04:32:43 -0700<br>From: "Richard D. Moores" &lt;<a ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>&gt;<br>To: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>Subject: [Tutor] What's the best way to model an unfair coin?<br>Message-ID:<br>&nbsp;&nbsp;&nbsp; &lt;AANLkTi=6LqiYuC+<a ymailto="mailto:ObUFcF0MrsDiPkPKZfv91QgAP3cHi@mail.gmail.com" href="/mc/compose?to=ObUFcF0MrsDiPkPKZfv91QgAP3cHi@mail.gmail.com">ObUFcF0MrsDiPkPKZfv91QgAP3cHi@mail.gmail.com</a>&gt;<br>Content-Type: text/plain; charset=UTF-8<br><br>What's the best way to model an unfair coin?<br><br>This is one way to do it, I suppose: Create a list containing only<br>'H's and 'T's. If you want the coin to have the probability of a head<br>to be 6/11,<br><br>['H', 'H', 'H', 'H', 'H', 'H', 'T', 'T',
 'T', 'T', 'T']<br><br>is the list to use. Use random.choice on the list, for a 6/11 heads<br>probability.<br><br>See &lt;<a href="http://tutoree7.pastebin.com/gxKYkYWW" target="_blank">http://tutoree7.pastebin.com/gxKYkYWW</a>&gt;.<br><br>That's the only way I can think of. But surely there's a better, more<br>general solution. What if the probability I want is an irrational<br>number, such as 1/e? Sure, I can calculate a fraction that's as close<br>to that irrational number as I want, but..<br><br>Am I missing something that's already there in Python 2.6 or 3.1 (the<br>2 I have)?<br><br>Dick Moores<br><br><br>------------------------------<br><br>Message: 3<br>Date: Sun, 24 Oct 2010 13:54:16 +0200<br>From: Evert Rol &lt;<a ymailto="mailto:evert.rol@gmail.com" href="/mc/compose?to=evert.rol@gmail.com">evert.rol@gmail.com</a>&gt;<br>To: "Richard D. Moores" &lt;<a ymailto="mailto:rdmoores@gmail.com"
 href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>&gt;<br>Cc: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>Subject: Re: [Tutor] What's the best way to model an unfair coin?<br>Message-ID: &lt;<a ymailto="mailto:1F4296E5-B373-43FD-B2A1-5B175CCE7263@gmail.com" href="/mc/compose?to=1F4296E5-B373-43FD-B2A1-5B175CCE7263@gmail.com">1F4296E5-B373-43FD-B2A1-5B175CCE7263@gmail.com</a>&gt;<br>Content-Type: text/plain; charset=us-ascii<br><br>&gt; What's the best way to model an unfair coin?<br>&gt; <br>&gt; This is one way to do it, I suppose: Create a list containing only<br>&gt; 'H's and 'T's. If you want the coin to have the probability of a head<br>&gt; to be 6/11,<br>&gt; <br>&gt; ['H', 'H', 'H', 'H', 'H', 'H', 'T', 'T', 'T', 'T', 'T']<br>&gt; <br>&gt; is the list to use. Use random.choice on the list, for a 6/11 heads<br>&gt; probability.<br>&gt; <br>&gt; See &lt;<a
 href="http://tutoree7.pastebin.com/gxKYkYWW" target="_blank">http://tutoree7.pastebin.com/gxKYkYWW</a>&gt;.<br>&gt; <br>&gt; That's the only way I can think of. But surely there's a better, more<br>&gt; general solution. What if the probability I want is an irrational<br>&gt; number, such as 1/e? Sure, I can calculate a fraction that's as close<br>&gt; to that irrational number as I want, but..<br><br>My statistics might be too rusty to have this correct, but I would do something similar as you have now, just not for integer numbers.<br>Assuming you only want True or False, you can use a uniform distribution, through random.random(), and see if the result is lower or higher than your probability. <br>Eg:<br><br>return random.random() &lt; 1/e<br><br>or <br><br>return random.random() &lt; 6/11.<br><br>will return True or False with your specificied probability. <br>Again, I just might be overlooking something in the
 statistics.<br><br>Cheers,<br><br>&nbsp; Evert<br><br>Btw, to be pedantic, 1/e is not an irrational number, just a real number. i/e would be.<br><br><br>&gt; <br>&gt; Am I missing something that's already there in Python 2.6 or 3.1 (the<br>&gt; 2 I have)?<br>&gt; <br>&gt; Dick Moores<br>&gt; _______________________________________________<br>&gt; Tutor maillist&nbsp; -&nbsp; <a ymailto="mailto:Tutor@python.org" href="/mc/compose?to=Tutor@python.org">Tutor@python.org</a><br>&gt; To unsubscribe or change subscription options:<br>&gt; <a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br><br>------------------------------<br><br>Message: 4<br>Date: Sun, 24 Oct 2010 04:56:11 -0700<br>From: "Richard D. Moores" &lt;<a ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>&gt;<br>To: col speed &lt;<a ymailto="mailto:ajarncolin@gmail.com"
 href="/mc/compose?to=ajarncolin@gmail.com">ajarncolin@gmail.com</a>&gt;<br>Cc: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>Subject: Re: [Tutor] What does "TypeError: 'int' object is not<br>&nbsp;&nbsp;&nbsp; iterable"&nbsp;&nbsp;&nbsp; mean?<br>Message-ID:<br>&nbsp;&nbsp;&nbsp; &lt;<a ymailto="mailto:AANLkTinYUep0SjSLv4AyiDxN0UZ3omygDiPOcPPR5xaD@mail.gmail.com" href="/mc/compose?to=AANLkTinYUep0SjSLv4AyiDxN0UZ3omygDiPOcPPR5xaD@mail.gmail.com">AANLkTinYUep0SjSLv4AyiDxN0UZ3omygDiPOcPPR5xaD@mail.gmail.com</a>&gt;<br>Content-Type: text/plain; charset=UTF-8<br><br>On Sat, Oct 23, 2010 at 02:28, col speed &lt;<a ymailto="mailto:ajarncolin@gmail.com" href="/mc/compose?to=ajarncolin@gmail.com">ajarncolin@gmail.com</a>&gt; wrote:<br>&gt;<br>&gt;<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; Message: 7<br>&gt;&gt; Date: Fri, 22 Oct 2010 21:48:29 -0700<br>&gt;&gt; From: "Richard D. Moores" &lt;<a
 ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>&gt;<br>&gt;&gt; To: "Steven D'Aprano" &lt;<a ymailto="mailto:steve@pearwood.info" href="/mc/compose?to=steve@pearwood.info">steve@pearwood.info</a>&gt;<br>&gt;&gt; Cc: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>&gt;&gt; Subject: Re: [Tutor] What does "TypeError: 'int' object is not<br>&gt;&gt; ? ? ? ?iterable" ? ? ? mean?<br>&gt;&gt; Message-ID:<br>&gt;&gt; ? ? ? ?&lt;AANLkTi=8EszCxYg-rAQBm0YyD=_dKVg4ZKoj+<a ymailto="mailto:e_QUXX5@mail.gmail.com" href="/mc/compose?to=e_QUXX5@mail.gmail.com">e_QUXX5@mail.gmail.com</a>&gt;<br>&gt;&gt; Content-Type: text/plain; charset=UTF-8<br>&gt;&gt;<br>&gt;&gt; It's great to have you chime in, Steven. I do wish you would stop<br>&gt;&gt; pulling your punches, however. ;)<br>&gt;&gt;<br>&gt;&gt; &lt;-snip&gt;<br>&gt;&gt; I've never seen that convention, but I'll
 try to follow it.<br>&gt;&gt;<br>&gt;&gt; &gt;<br>&gt;&gt; &gt; (BTW, I really hate the name "floatt". It makes me think you're<br>&gt;&gt; &gt; stuttering.)<br>&gt;&gt;<br>&gt;&gt; I'll use "x" instead. Anything you'd like to say about the rest of the<br>&gt;&gt; script?<br>&gt;&gt;<br>&gt;&gt; Thanks, Steven.<br>&gt;&gt;<br>&gt;&gt; Dick<br>&gt;&gt;<br>&gt;&gt;<br>&gt;&gt; ------------------------------<br>&gt;&gt; Excuse me, I'm not a professional. Rather than "x", I would use "float_"<br>&gt;&gt; or even "not_int", as mentioned in PEP8:<br>&gt;<br>&gt; If a function argument's name clashes with a reserved keyword, it is<br>&gt;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;generally better to append a single trailing underscore rather than<br>&gt; use<br>&gt;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;an abbreviation or spelling corruption.&nbsp; Thus "print_" is better than<br>&gt;<br>&gt; "prnt". (Perhaps better is to avoid such clashes by using a synonym.)<br>&gt; Steven
 knows his subject, please don't answer like this.<br><br>And I have a request of you: Please don't change the Subject header<br>when you reply. I didn't see your post with it's important suggestion<br>until just now.<br><br>Thanks for the quote from PEP8.&nbsp; I went with "myfloat", on Dave<br>Angel's suggestion, but float_ looks good as well. 'not_int' is not so<br>good, because many kinds of objects are "not_int"s.<br><br>As for Steven, you're absolutely correct -- and I've learned a lot from him.<br><br>Dave Angel wrote:<br>&gt; Sometimes Steven's style can be a bit caustic, but there's almost always a<br>&gt; few important nuggets.<br><br>and I replied:<br>&gt;Absolutely there are! And I have no problem with his style. I just<br>&gt;couldn't hold back what I intended to be a gentle jab of sarcasm.<br>&gt;Dangerous in email--especially an email list.<br><br>Dick<br><br><br>------------------------------<br><br>Message: 5<br>Date: Sun, 24 Oct 2010
 23:17:13 +1100<br>From: Steven D'Aprano &lt;<a ymailto="mailto:steve@pearwood.info" href="/mc/compose?to=steve@pearwood.info">steve@pearwood.info</a>&gt;<br>To: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>Subject: Re: [Tutor] What's the best way to model an unfair coin?<br>Message-ID: &lt;<a ymailto="mailto:4CC423C9.5050500@pearwood.info" href="/mc/compose?to=4CC423C9.5050500@pearwood.info">4CC423C9.5050500@pearwood.info</a>&gt;<br>Content-Type: text/plain; charset=UTF-8; format=flowed<br><br>Richard D. Moores wrote:<br>&gt; What's the best way to model an unfair coin?<br><br>Let probability of heads = p, where 0 &lt;= p &lt;= 1<br>Then probability of tails = 1-p.<br><br>if random.random() &lt;= p: print("got heads")<br>else: print("got tails")<br><br>[...]<br>&gt; That's the only way I can think of. But surely there's a better, more<br>&gt; general solution. What if the probability I want is an
 irrational<br>&gt; number, such as 1/e? Sure, I can calculate a fraction that's as close<br>&gt; to that irrational number as I want, but..<br><br>Well, technically speaking all floats in Python are rational numbers, <br>since they're base-2 floating point numbers. But the difference between <br>(say) float pi and the true irrational number ? is around about<br>0.0000000000000001, so close enough for most purposes.<br><br><br><br>-- <br>Steven<br><br><br><br>------------------------------<br><br>Message: 6<br>Date: Sun, 24 Oct 2010 13:18:52 +0100<br>From: "Alan Gauld" &lt;<a ymailto="mailto:alan.gauld@btinternet.com" href="/mc/compose?to=alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>&gt;<br>To: <a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a><br>Subject: Re: [Tutor] What's the best way to model an unfair coin?<br>Message-ID: &lt;ia187j$fa7$<a ymailto="mailto:1@dough.gmane.org"
 href="/mc/compose?to=1@dough.gmane.org">1@dough.gmane.org</a>&gt;<br>Content-Type: text/plain; format=flowed; charset="iso-8859-1";<br>&nbsp;&nbsp;&nbsp; reply-type=original<br><br><br>"Richard D. Moores" &lt;<a ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>&gt; wrote<br><br>&gt; 'H's and 'T's. If you want the coin to have the probability of a <br>&gt; head<br>&gt; to be 6/11,<br>&gt;<br>&gt; ['H', 'H', 'H', 'H', 'H', 'H', 'T', 'T', 'T', 'T', 'T']<br>&gt;<br>&gt; is the list to use. Use random.choice on the list, for a 6/11 heads<br>&gt; probability.<br><br>That will work but as you say is not very general.<br>You could write a function that takers the desired probablity<br>as an input and returns a result based on that.<br><br>The simplest way its to generate a random number between<br>0 and 1 and compare to the required probability expressed<br>as a decimal fraction.<br><br>In pseudo
 code:<br><br>def coinToss(prob = 0.5):<br>&nbsp; &nbsp; rand = random()<br>&nbsp; &nbsp; if rand &gt;= prob: return True<br>&nbsp; &nbsp; else: return False<br><br>print "Heads" if coinToss(6/11) else "Tails"<br><br><br>&gt; Am I missing something that's already there in Python 2.6 or 3.1 <br>&gt; (the<br>&gt; 2 I have)?<br><br>There may well be functions in some of the modules that do it but<br>the approach above suffices for most applications.<br><br>HTH,<br><br>-- <br>Alan Gauld<br>Author of the Learn to Program web site<br><a href="http://www.alan-g.me.uk/" target="_blank">http://www.alan-g.me.uk/</a><br><br><br><br><br>------------------------------<br><br>Message: 7<br>Date: Sun, 24 Oct 2010 14:24:14 +0200<br>From: Evert Rol &lt;<a ymailto="mailto:evert.rol@gmail.com" href="/mc/compose?to=evert.rol@gmail.com">evert.rol@gmail.com</a>&gt;<br>To: "Richard D. Moores" &lt;<a ymailto="mailto:rdmoores@gmail.com"
 href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>&gt;,&nbsp;&nbsp;&nbsp; python mail list<br>&nbsp;&nbsp;&nbsp; &lt;<a ymailto="mailto:tutor@python.org" href="/mc/compose?to=tutor@python.org">tutor@python.org</a>&gt;<br>Subject: Re: [Tutor] What's the best way to model an unfair coin?<br>Message-ID: &lt;<a ymailto="mailto:640D24EC-1CA0-47FA-83F3-72A8E6CD5DB5@gmail.com" href="/mc/compose?to=640D24EC-1CA0-47FA-83F3-72A8E6CD5DB5@gmail.com">640D24EC-1CA0-47FA-83F3-72A8E6CD5DB5@gmail.com</a>&gt;<br>Content-Type: text/plain; charset=us-ascii<br><br>&gt; Btw, to be pedantic, 1/e is not an irrational number, just a real number. i/e would be.<br><br>My bad: irrational != imaginary. And real = irrational.<br>Things are definitely a bit rusty...<br><br><br><br><br>------------------------------<br><br>_______________________________________________<br>Tutor maillist&nbsp; -&nbsp; <a ymailto="mailto:Tutor@python.org"
 href="/mc/compose?to=Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br><br><br>End of Tutor Digest, Vol 80, Issue 108<br>**************************************<br></div></blockquote></td></tr></table><br>