On 28/08/2021 21:50, Hope Rouselle wrote:

>>> roll_count = 0
>>> while True:
>>>     outcome = roll_two_dice()
>>>     roll_count += 1
>>>     if outcome[ 0 ]== outcome[ 1 ]: break
>>> return roll_count, outcome[ 0 ]
>>
> 
> Wait, I'm surprised ``outcome'' is still a valid name at the
> return-statement.  Wasn't it defined inside the while?  

If that really bugs you just replace the break with the return.


>>>     if outcome[ 0 ]== outcome[ 1 ]:
>>>        return roll_count, outcome[ 0 ]

Now its all inside the loop.

But remember readable code is better than  cute code every time.
And personally I'd just declare the x,y up front. Easier to
understand and debug IMHO.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to