Open Question - I'm a complete novice in programming so please bear with me...Is python equivalent to C, C++ and java combined?

Chris Angelico rosuav at gmail.com
Sun Jan 12 09:44:28 EST 2014


On Mon, Jan 13, 2014 at 1:36 AM, Rotwang <sg552 at hotmail.co.uk> wrote:
> On 12/01/2014 05:58, Chris Angelico wrote:
>>
>> (BTW, is there no better notation than six nested for/range for doing
>> 6d6? I couldn't think of one off-hand, but it didn't really much
>> matter anyway.)
>
>
> If you're willing to do an import, then how about this:
>
>>>> from itertools import product
>>>> len([x for x in product(range(1, 7), repeat = 6) if sum(x) < 14])/6**6
> 0.03587962962962963

Should have known itertools would have something. That's a little more
complicated to try to explain, but it's a lot shorter.

ChrisA



More information about the Python-list mailing list