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