Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77002 > unrolled thread

This formating is really tricky

Started bySeymore4Head <Seymore4Head@Hotmail.invalid>
First post2014-08-25 16:14 -0400
Last post2014-08-26 14:50 -0400
Articles 20 on this page of 33 — 14 participants

Back to article view | Back to comp.lang.python


Contents

  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

Page 1 of 2  [1] 2  Next page →


#77002 — This formating is really tricky

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-25 16:14 -0400
SubjectThis formating is really tricky
Message-ID<na5nv9l1slfkh4038ppc6779pbgajbbt19@4ax.com>
import random
sets=3
for x in range(0, sets):

pb1=random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53])
    pb2=random.choice([1-53])

pb3=random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53])

pb4=random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53])

pb5=random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53])

pb6=random.choice([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42])


    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

Suggestion please?

BTW the exercise instructions say to use the choice function.  I
assume I had to include all the numbers to choose from instead of
picking a random number from 1-53 or 1-42.

I included my shortcut for pb2.  It doesn't work?  Is there a short to
prevent from listing each number?

[toc] | [next] | [standalone]


#77003

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-08-25 21:52 +0100
Message-ID<mailman.13432.1408999958.18130.python-list@python.org>
In reply to#77002
On 25/08/2014 21:14, Seymore4Head wrote:
>
> I included my shortcut for pb2.  It doesn't work?  Is there a short to
> prevent from listing each number?
>

If it doesn't work then fix it and it will work.  Alternatively define 
what "it doesn't work" means as I've run out of crystal balls, every 
single one of them is u/s.  I've been working them so hard recently 
because not enough newbies provide the data we need to work with.

Another choice is to go away and read one of hundreds of Python 
tutorials.  There's a fair chance that one of them will cover what you 
need to know.  Here for example is a rather obscure one that I first 
stumbled across many moons ago https://docs.python.org/3/tutorial/index.html

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#77020

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-25 23:12 -0400
Message-ID<bmunv9dnqo86usic4s3otf1fr225o0565b@4ax.com>
In reply to#77003
On Mon, 25 Aug 2014 21:52:24 +0100, Mark Lawrence
<breamoreboy@yahoo.co.uk> wrote:

>On 25/08/2014 21:14, Seymore4Head wrote:
>>
>> I included my shortcut for pb2.  It doesn't work?  Is there a short to
>> prevent from listing each number?
>>
>
>If it doesn't work then fix it and it will work.  Alternatively define 
>what "it doesn't work" means as I've run out of crystal balls, every 
>single one of them is u/s.  I've been working them so hard recently 
>because not enough newbies provide the data we need to work with.
>
>Another choice is to go away and read one of hundreds of Python 
>tutorials.  There's a fair chance that one of them will cover what you 
>need to know.  Here for example is a rather obscure one that I first 
>stumbled across many moons ago https://docs.python.org/3/tutorial/index.html

I will give that a try.
I already know I have trouble explaining myself.  It makes it even
harder when I don't know what I am talking about.

Sorry

[toc] | [prev] | [next] | [standalone]


#77004

FromRustom Mody <rustompmody@gmail.com>
Date2014-08-25 14:05 -0700
Message-ID<b2febe9d-5695-42d5-ae29-c5421715b68c@googlegroups.com>
In reply to#77002
On Tuesday, August 26, 2014 1:44:40 AM UTC+5:30, Seymore4Head wrote:
> BTW the exercise instructions say to use the choice function.  I
> assume I had to include all the numbers to choose from instead of
> picking a random number from 1-53 or 1-42.

> I included my shortcut for pb2.  It doesn't work?  Is there a short to
> prevent from listing each number?

Yeah I guess googling for that will not work well if you say "listing each 
number"

$ python
Python 2.7.8 (default, Aug 10 2014, 16:19:34) 
[GCC 4.9.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> range(1,54)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53]


It may help to do
>>> help(range)

[toc] | [prev] | [next] | [standalone]


#77021

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-25 23:14 -0400
Message-ID<lpunv99ga1386vm3sshc01etc0fq29t0h7@4ax.com>
In reply to#77004
On Mon, 25 Aug 2014 14:05:01 -0700 (PDT), Rustom Mody
<rustompmody@gmail.com> wrote:

>On Tuesday, August 26, 2014 1:44:40 AM UTC+5:30, Seymore4Head wrote:
>> BTW the exercise instructions say to use the choice function.  I
>> assume I had to include all the numbers to choose from instead of
>> picking a random number from 1-53 or 1-42.
>
>> I included my shortcut for pb2.  It doesn't work?  Is there a short to
>> prevent from listing each number?
>
>Yeah I guess googling for that will not work well if you say "listing each 
>number"
>
>$ python
>Python 2.7.8 (default, Aug 10 2014, 16:19:34) 
>[GCC 4.9.1] on linux2
>Type "help", "copyright", "credits" or "license" for more information.
>
>>>> range(1,54)
>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53]
>
>
>It may help to do
>>>> help(range)

There is lots of help built in.  Trying to read all the options makes
me realize the stuff I am working on is just the tip of the iceberg.
When checking the help function, it is clear I will never get to about
90% of the features.

Thanks

[toc] | [prev] | [next] | [standalone]


#77110

FromLarry Hudson <orgnut@yahoo.com>
Date2014-08-26 23:46 -0700
Message-ID<2sudnYPLgsN-42DOnZ2dnUU7-L-dnZ2d@giganews.com>
In reply to#77021
On 08/25/2014 08:14 PM, Seymore4Head wrote:
[snip]
> There is lots of help built in.  Trying to read all the options makes
> me realize the stuff I am working on is just the tip of the iceberg.
> When checking the help function, it is clear I will never get to about
> 90% of the features.
>
> Thanks
>

That's why we keep telling you to FIRST go through a basic tutorial.  It will start at the 
beginning and work up.  You will really find you will learn the language that way much MUCH 
faster than trying to pick things up piecemeal by asking totally isolated questions.

And... (from another post)

 > pb2=random.choice([1-53])
 >
 > I included my shortcut for pb2.  It doesn't work?  Is there a short to
 > prevent from listing each number?

Of course it doesn't work!  That list has only one element, the integer -52.

Now go through a tutorial to find out what to do about it.

      -=- Larry -=-

[toc] | [prev] | [next] | [standalone]


#77129

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-27 09:36 -0400
Message-ID<1nnrv9ltugghcfg9ac8v0hlc5gjrhv468k@4ax.com>
In reply to#77110
On Tue, 26 Aug 2014 23:46:58 -0700, Larry Hudson <orgnut@yahoo.com>
wrote:

>On 08/25/2014 08:14 PM, Seymore4Head wrote:
>[snip]
>> There is lots of help built in.  Trying to read all the options makes
>> me realize the stuff I am working on is just the tip of the iceberg.
>> When checking the help function, it is clear I will never get to about
>> 90% of the features.
>>
>> Thanks
>>
>
>That's why we keep telling you to FIRST go through a basic tutorial.  It will start at the 
>beginning and work up.  You will really find you will learn the language that way much MUCH 
>faster than trying to pick things up piecemeal by asking totally isolated questions.
>
>And... (from another post)
>
> > pb2=random.choice([1-53])
> >
> > I included my shortcut for pb2.  It doesn't work?  Is there a short to
> > prevent from listing each number?
>
>Of course it doesn't work!  That list has only one element, the integer -52.
>
>Now go through a tutorial to find out what to do about it.
>
>      -=- Larry -=-
Will do.
Thanks

[toc] | [prev] | [next] | [standalone]


#77006

FromTerry Reedy <tjreedy@udel.edu>
Date2014-08-25 18:22 -0400
Message-ID<mailman.13434.1409005368.18130.python-list@python.org>
In reply to#77002
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)
...
>      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 ;=)

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#77011

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-25 20:51 -0400
Message-ID<cklnv9tb6kfsouucpslkgninao0h5jstiv@4ax.com>
In reply to#77006
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.


>>      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.  

[toc] | [prev] | [next] | [standalone]


#77014

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-25 21:16 -0400
Message-ID<dsnnv9dlt3m23131amhvraf6ia263cnaop@4ax.com>
In reply to#77011
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.  

[toc] | [prev] | [next] | [standalone]


#77069

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-26 15:31 -0400
Message-ID<osnpv9lj7ra5ho4pco48jqnmas25nal7gj@4ax.com>
In reply to#77006
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)
>...
>>      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()))
>
I modified your code to only use lotto numbers that don't repeat.  I
am sure there is a more elegant way to this too.

import random
sets=10
print ("How many sets of numbers? ",sets)

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(random.randint(1, 53) for i in range(5))
     if balls[0]!= balls[1] and balls[1]!= balls[2] and balls[2]!=
balls[3] and balls[3]!= balls[4]:
          print(bform.format(*balls), pform.format(random.randint(1,
42)))
     sets=sets-1
     
Thanks

>> 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 ;=)

[toc] | [prev] | [next] | [standalone]


#77111

FromPeter Otten <__peter__@web.de>
Date2014-08-27 09:16 +0200
Message-ID<mailman.13493.1409123816.18130.python-list@python.org>
In reply to#77069
Seymore4Head 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)
>>...
>>>      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()))
>>
> I modified your code to only use lotto numbers that don't repeat.  I
> am sure there is a more elegant way to this too.
> 
> import random
> sets=10
> print ("How many sets of numbers? ",sets)
> 
> 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(random.randint(1, 53) for i in range(5))
>      if balls[0]!= balls[1] and balls[1]!= balls[2] and balls[2]!=
> balls[3] and balls[3]!= balls[4]:

A simpler test would be

       if len(set(balls)) == 5:

>           print(bform.format(*balls), pform.format(random.randint(1,
> 42)))
>      sets=sets-1

It's not just elegance, the code is incorrect as it can print less than 10 
sets.

Replace the for loop with a while loop, and only decrease sets when you 
print a valid draw.

[toc] | [prev] | [next] | [standalone]


#77128

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-27 09:35 -0400
Message-ID<2lnrv95mdkvkiul76746ts6k0lmdkrq30d@4ax.com>
In reply to#77111
On Wed, 27 Aug 2014 09:16:43 +0200, Peter Otten <__peter__@web.de>
wrote:

>Seymore4Head 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)
>>>...
>>>>      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()))
>>>
>> I modified your code to only use lotto numbers that don't repeat.  I
>> am sure there is a more elegant way to this too.
>> 
>> import random
>> sets=10
>> print ("How many sets of numbers? ",sets)
>> 
>> 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(random.randint(1, 53) for i in range(5))
>>      if balls[0]!= balls[1] and balls[1]!= balls[2] and balls[2]!=
>> balls[3] and balls[3]!= balls[4]:
>
>A simpler test would be
>
>       if len(set(balls)) == 5:
>
>>           print(bform.format(*balls), pform.format(random.randint(1,
>> 42)))
>>      sets=sets-1
>
>It's not just elegance, the code is incorrect as it can print less than 10 
>sets.
>
>Replace the for loop with a while loop, and only decrease sets when you 
>print a valid draw.
>
I will give those suggestions a try.
Thanks

[toc] | [prev] | [next] | [standalone]


#77007

FromPeter Otten <__peter__@web.de>
Date2014-08-26 00:48 +0200
Message-ID<mailman.13435.1409006947.18130.python-list@python.org>
In reply to#77002
Terry Reedy 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)
> ...
>>      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))

Quoting the problem description: "The first five numbers are drawn from a 
drum containing 53 balls"

Thus no number should repeat in the first five. With your approach such 
repetitions can happen. The simplest solution is of course

random.sample(range(1, 54), 5)

but the OP will learn more when he tries to figure out how to get a correct 
solution with choice().

[toc] | [prev] | [next] | [standalone]


#77012

FromSeymore4Head <Seymore4Head@Hotmail.invalid>
Date2014-08-25 20:52 -0400
Message-ID<8imnv9l638q9hsvvib28t8qp0depa8rb7c@4ax.com>
In reply to#77007
On Tue, 26 Aug 2014 00:48:52 +0200, Peter Otten <__peter__@web.de>
wrote:

>Terry Reedy 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)
>> ...
>>>      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))
>
>Quoting the problem description: "The first five numbers are drawn from a 
>drum containing 53 balls"
>
>Thus no number should repeat in the first five. With your approach such 
>repetitions can happen. The simplest solution is of course
>
>random.sample(range(1, 54), 5)
>
>but the OP will learn more when he tries to figure out how to get a correct 
>solution with choice().
>
Don't bet on it.  :)

[toc] | [prev] | [next] | [standalone]


#77016

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2014-08-25 21:10 -0400
Message-ID<mailman.13438.1409015454.18130.python-list@python.org>
In reply to#77012
you should try python-tudor mailing list

On Mon, Aug 25, 2014 at 8:52 PM, Seymore4Head
<Seymore4Head@hotmail.invalid> wrote:
> On Tue, 26 Aug 2014 00:48:52 +0200, Peter Otten <__peter__@web.de>
> wrote:
>
>>Terry Reedy 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)
>>> ...
>>>>      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))
>>
>>Quoting the problem description: "The first five numbers are drawn from a
>>drum containing 53 balls"
>>
>>Thus no number should repeat in the first five. With your approach such
>>repetitions can happen. The simplest solution is of course
>>
>>random.sample(range(1, 54), 5)
>>
>>but the OP will learn more when he tries to figure out how to get a correct
>>solution with choice().
>>
> Don't bet on it.  :)
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#77026

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2014-08-26 18:17 +1200
Message-ID<c62n3dFn8lnU1@mid.individual.net>
In reply to#77016
Joel Goldstick wrote:
> you should try python-tudor mailing list
                         ^^^^^
Hmmm. I wonder what version of Python Henry VIII used?

-- 
Greg

[toc] | [prev] | [next] | [standalone]


#77027

FromChris Angelico <rosuav@gmail.com>
Date2014-08-26 16:22 +1000
Message-ID<mailman.13442.1409034160.18130.python-list@python.org>
In reply to#77026
On Tue, Aug 26, 2014 at 4:17 PM, Gregory Ewing
<greg.ewing@canterbury.ac.nz> wrote:
> Joel Goldstick wrote:
>>
>> you should try python-tudor mailing list
>
>                         ^^^^^
> Hmmm. I wonder what version of Python Henry VIII used?

Version 8.0, in a modern numbering scheme. See, those letters after
his name are called "Roman numerals", and in their own special way,
they represent numbers...

ChrisA

[toc] | [prev] | [next] | [standalone]


#77033

Fromalister <alister.nospam.ware@ntlworld.com>
Date2014-08-26 09:27 +0000
Message-ID<PpYKv.75530$rb.17725@fx16.am4>
In reply to#77016
On Mon, 25 Aug 2014 21:10:47 -0400, Joel Goldstick wrote:

> you should try python-tudor mailing list
> 
Oh Wow I didn't know Python was that old - it even pre-dates 
Electricity :-)

-- 
Hand, n.:
	A singular instrument worn at the end of a human arm and
	commonly thrust into somebody's pocket.
		-- Ambrose Bierce, "The Devil's Dictionary"

[toc] | [prev] | [next] | [standalone]


#77034

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-08-26 12:32 +0300
Message-ID<87iolfha01.fsf@elektro.pacujo.net>
In reply to#77033
alister <alister.nospam.ware@ntlworld.com>:

> Oh Wow I didn't know Python was that old - it even pre-dates 
> Electricity :-)

Electricity arose already before the Great Inflation.


Marko

[toc] | [prev] | [next] | [standalone]


Page 1 of 2  [1] 2  Next page →

Back to top | Article view | comp.lang.python


csiph-web