Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77014
| From | Seymore4Head <Seymore4Head@Hotmail.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: This formating is really tricky |
| Date | 2014-08-25 21:16 -0400 |
| Message-ID | <dsnnv9dlt3m23131amhvraf6ia263cnaop@4ax.com> (permalink) |
| References | <na5nv9l1slfkh4038ppc6779pbgajbbt19@4ax.com> <mailman.13434.1409005368.18130.python-list@python.org> <cklnv9tb6kfsouucpslkgninao0h5jstiv@4ax.com> |
| Organization | Unlimited download news at news.astraweb.com |
On Mon, 25 Aug 2014 20:51:36 -0400, Seymore4Head
<Seymore4Head@Hotmail.invalid> wrote:
>On Mon, 25 Aug 2014 18:22:35 -0400, Terry Reedy <tjreedy@udel.edu>
>wrote:
>
>>On 8/25/2014 4:14 PM, Seymore4Head wrote:
>>> import random
>>> sets=3
>>> for x in range(0, sets):
>>> pb2=random.choice([1-53])
>>
>>You want random.randint(1, 53)
>>...
>I agree with you that random.randint would be what I would use too,
>but the instructions say to use choice. The thing is, the next
>tutorial is rock paper scissors.
>
>Using "choice" for rock paper scissors does seem better as you can
>use:
>computer=random.choice(["Rock","Paper","Scissors"])
>
>BTW In my trial and error endeavors I tried:
>random.choice([1,53]) for a shortcut.
>It seems to work. That brings up another question. What would you
>use if you only wanted those two choices? 1 and 53.
>I guess if you tried 53,1 it might work.
>
Actually, neither random.choice([1,53] or random.choice([53,1] work
for a shortcut. Seeing the numbers sorted threw me off when I ran the
program.
>>> alist = sorted([pb1, pb2, pb3, pb4, pb5])
>>> print ("Your numbers: {} Powerball: {}".format(alist, pb6))
>>>
>>> I am trying this example. The program works, but the numbers don't
>>> line up if the number of digits are different sizes.
>>> http://openbookproject.net/pybiblio/practice/wilson/powerball.php
>>
>>To get them to line up, you have to format each one to the same width.
>>
>>> Suggestion please?
>>> BTW the exercise instructions say to use the choice function.
>>
>>import random
>>sets=3
>>
>>def ran53():
>> return random.randint(1, 53)
>>
>>f1 = '{:2d}'
>>bform = "Your numbers: [{0}, {0}, {0}, {0}, {0}]".format(f1)
>>pform = " Powerball: {0}".format(f1)
>>
>>for x in range(0, sets):
>> balls = sorted(ran53() for i in range(5))
>> print(bform.format(*balls), pform.format(ran53()))
>>
>>> BTW the exercise instructions say to use the choice function.
>>
>>I am not a fan of exercises that say to do something the wrong way, but
>>if you really had to,
>>
>>n54 = [i for i in range(1, 54)]
>>random.choice(n54)
>>
>>An alternative to choosing numbers is to choose from 2-char number strings.
>>
>>n53 = ['%2d' % i for i in range(1, 54)]
>>
>>But then you have to figure out how to avoid having 6 pairs of quotes in
>>the output ;=)
>
>I replied before I had a chance to try any of it. Maybe the
>random.choice questions get answered after trying your suggestions.
>
>Thanks for you suggestions.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 16:14 -0400
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-25 21:52 +0100
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 23:12 -0400
Re: This formating is really tricky Rustom Mody <rustompmody@gmail.com> - 2014-08-25 14:05 -0700
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 23:14 -0400
Re: This formating is really tricky Larry Hudson <orgnut@yahoo.com> - 2014-08-26 23:46 -0700
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-27 09:36 -0400
Re: This formating is really tricky Terry Reedy <tjreedy@udel.edu> - 2014-08-25 18:22 -0400
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 20:51 -0400
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 21:16 -0400
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-26 15:31 -0400
Re: This formating is really tricky Peter Otten <__peter__@web.de> - 2014-08-27 09:16 +0200
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-27 09:35 -0400
Re: This formating is really tricky Peter Otten <__peter__@web.de> - 2014-08-26 00:48 +0200
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 20:52 -0400
Re: This formating is really tricky Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-25 21:10 -0400
Re: This formating is really tricky Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-26 18:17 +1200
Re: This formating is really tricky Chris Angelico <rosuav@gmail.com> - 2014-08-26 16:22 +1000
Re: This formating is really tricky alister <alister.nospam.ware@ntlworld.com> - 2014-08-26 09:27 +0000
Re: This formating is really tricky Marko Rauhamaa <marko@pacujo.net> - 2014-08-26 12:32 +0300
Re: This formating is really tricky alister <alister.nospam.ware@ntlworld.com> - 2014-08-26 10:32 +0000
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-26 06:57 +0100
Re: This formating is really tricky MRAB <python@mrabarnett.plus.com> - 2014-08-26 12:24 +0100
Re: This formating is really tricky Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-26 09:28 -0400
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-26 17:09 +0100
Re: This formating is really tricky Chris Angelico <rosuav@gmail.com> - 2014-08-27 02:13 +1000
Re: This formating is really tricky Peter Otten <__peter__@web.de> - 2014-08-26 18:28 +0200
Re: This formating is really tricky Chris Angelico <rosuav@gmail.com> - 2014-08-27 02:33 +1000
Re: This formating is really tricky Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-26 18:19 +0100
Re: This formating is really tricky Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-08-27 09:39 +1200
Re: This formating is really tricky Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-26 12:45 +1000
Re: This formating is really tricky Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-25 23:10 -0400
Re: This formating is really tricky Gene Heskett <gheskett@wdtv.com> - 2014-08-26 14:50 -0400
csiph-web