<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">mai date in pula mea cu masurile tale mai acrit la coie mai termina in plm cu ele<br><br>--- On <b>Sun, 10/24/10, tutor-request@python.org <i><tutor-request@python.org></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 <tutor-request@python.org><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> <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> <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> <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> <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> 1. Re: Scripting-Puzzle Pirates (Lie Ryan)<br> 2. What's the best way to model an unfair coin? (Richard D. Moores)<br> 3. Re: What's the best way to model an unfair coin? (Evert Rol)<br> 4. Re: What does "TypeError: 'int' object is not iterable" mean?<br>
(Richard D. Moores)<br> 5. Re: What's the best way to model an unfair coin? (Steven D'Aprano)<br> 6. Re: What's the best way to model an unfair coin? (Alan Gauld)<br> 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 <<a ymailto="mailto:lie.1296@gmail.com" href="/mc/compose?to=lie.1296@gmail.com">lie.1296@gmail.com</a>><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: <ia13ff$t9m$<a ymailto="mailto:1@dough.gmane.org" href="/mc/compose?to=1@dough.gmane.org">1@dough.gmane.org</a>><br>Content-Type: text/plain; charset=ISO-8859-1<br><br>On 10/24/10 15:33, Nathan Finney wrote:<br>>
Hey,<br>> <br>> So I got bored of having to do a repeated task on this game, YPP Puzzle<br>> 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>> My task<br>> would be to start at a dock, click on the port arrow, choose a ship (a<br>> different one each time and in order preferably), go to its hold, select<br>> materials to be moved and move them to a set ship (the same one each<br>> 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>> If this is possible would I first need a set of the games coding (which<br>> uses javascript) to be obtained so it could be read and a script used<br>> 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" <<a ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>><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> <AANLkTi=6LqiYuC+<a ymailto="mailto:ObUFcF0MrsDiPkPKZfv91QgAP3cHi@mail.gmail.com" href="/mc/compose?to=ObUFcF0MrsDiPkPKZfv91QgAP3cHi@mail.gmail.com">ObUFcF0MrsDiPkPKZfv91QgAP3cHi@mail.gmail.com</a>><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 <<a href="http://tutoree7.pastebin.com/gxKYkYWW" target="_blank">http://tutoree7.pastebin.com/gxKYkYWW</a>>.<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 <<a ymailto="mailto:evert.rol@gmail.com" href="/mc/compose?to=evert.rol@gmail.com">evert.rol@gmail.com</a>><br>To: "Richard D. Moores" <<a ymailto="mailto:rdmoores@gmail.com"
href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>><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: <<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>><br>Content-Type: text/plain; charset=us-ascii<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 <<a
href="http://tutoree7.pastebin.com/gxKYkYWW" target="_blank">http://tutoree7.pastebin.com/gxKYkYWW</a>>.<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>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() < 1/e<br><br>or <br><br>return random.random() < 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> 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>> <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>> Tutor maillist - <a ymailto="mailto:Tutor@python.org" href="/mc/compose?to=Tutor@python.org">Tutor@python.org</a><br>> To unsubscribe or change subscription options:<br>> <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" <<a ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>><br>To: col speed <<a ymailto="mailto:ajarncolin@gmail.com"
href="/mc/compose?to=ajarncolin@gmail.com">ajarncolin@gmail.com</a>><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> iterable" mean?<br>Message-ID:<br> <<a ymailto="mailto:AANLkTinYUep0SjSLv4AyiDxN0UZ3omygDiPOcPPR5xaD@mail.gmail.com" href="/mc/compose?to=AANLkTinYUep0SjSLv4AyiDxN0UZ3omygDiPOcPPR5xaD@mail.gmail.com">AANLkTinYUep0SjSLv4AyiDxN0UZ3omygDiPOcPPR5xaD@mail.gmail.com</a>><br>Content-Type: text/plain; charset=UTF-8<br><br>On Sat, Oct 23, 2010 at 02:28, col speed <<a ymailto="mailto:ajarncolin@gmail.com" href="/mc/compose?to=ajarncolin@gmail.com">ajarncolin@gmail.com</a>> wrote:<br>><br>><br>>><br>>><br>>> Message: 7<br>>> Date: Fri, 22 Oct 2010 21:48:29 -0700<br>>> From: "Richard D. Moores" <<a
ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>><br>>> To: "Steven D'Aprano" <<a ymailto="mailto:steve@pearwood.info" href="/mc/compose?to=steve@pearwood.info">steve@pearwood.info</a>><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>>> ? ? ? ?iterable" ? ? ? mean?<br>>> Message-ID:<br>>> ? ? ? ?<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>><br>>> Content-Type: text/plain; charset=UTF-8<br>>><br>>> It's great to have you chime in, Steven. I do wish you would stop<br>>> pulling your punches, however. ;)<br>>><br>>> <-snip><br>>> I've never seen that convention, but I'll
try to follow it.<br>>><br>>> ><br>>> > (BTW, I really hate the name "floatt". It makes me think you're<br>>> > stuttering.)<br>>><br>>> I'll use "x" instead. Anything you'd like to say about the rest of the<br>>> script?<br>>><br>>> Thanks, Steven.<br>>><br>>> Dick<br>>><br>>><br>>> ------------------------------<br>>> Excuse me, I'm not a professional. Rather than "x", I would use "float_"<br>>> or even "not_int", as mentioned in PEP8:<br>><br>> If a function argument's name clashes with a reserved keyword, it is<br>> generally better to append a single trailing underscore rather than<br>> use<br>> an abbreviation or spelling corruption. Thus "print_" is better than<br>><br>> "prnt". (Perhaps better is to avoid such clashes by using a synonym.)<br>> 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. 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>> Sometimes Steven's style can be a bit caustic, but there's almost always a<br>> few important nuggets.<br><br>and I replied:<br>>Absolutely there are! And I have no problem with his style. I just<br>>couldn't hold back what I intended to be a gentle jab of sarcasm.<br>>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 <<a ymailto="mailto:steve@pearwood.info" href="/mc/compose?to=steve@pearwood.info">steve@pearwood.info</a>><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: <<a ymailto="mailto:4CC423C9.5050500@pearwood.info" href="/mc/compose?to=4CC423C9.5050500@pearwood.info">4CC423C9.5050500@pearwood.info</a>><br>Content-Type: text/plain; charset=UTF-8; format=flowed<br><br>Richard D. Moores wrote:<br>> What's the best way to model an unfair coin?<br><br>Let probability of heads = p, where 0 <= p <= 1<br>Then probability of tails = 1-p.<br><br>if random.random() <= p: print("got heads")<br>else: print("got tails")<br><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>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" <<a ymailto="mailto:alan.gauld@btinternet.com" href="/mc/compose?to=alan.gauld@btinternet.com">alan.gauld@btinternet.com</a>><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: <ia187j$fa7$<a ymailto="mailto:1@dough.gmane.org"
href="/mc/compose?to=1@dough.gmane.org">1@dough.gmane.org</a>><br>Content-Type: text/plain; format=flowed; charset="iso-8859-1";<br> reply-type=original<br><br><br>"Richard D. Moores" <<a ymailto="mailto:rdmoores@gmail.com" href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>> wrote<br><br>> 'H's and 'T's. If you want the coin to have the probability of a <br>> 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>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> rand = random()<br> if rand >= prob: return True<br> else: return False<br><br>print "Heads" if coinToss(6/11) else "Tails"<br><br><br>> Am I missing something that's already there in Python 2.6 or 3.1 <br>> (the<br>> 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 <<a ymailto="mailto:evert.rol@gmail.com" href="/mc/compose?to=evert.rol@gmail.com">evert.rol@gmail.com</a>><br>To: "Richard D. Moores" <<a ymailto="mailto:rdmoores@gmail.com"
href="/mc/compose?to=rdmoores@gmail.com">rdmoores@gmail.com</a>>, python mail list<br> <<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: <<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>><br>Content-Type: text/plain; charset=us-ascii<br><br>> 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 - <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>