[Tutor] bubble sort function

Sunil Tech sunil.techspk at gmail.com
Wed Nov 26 12:16:11 CET 2014


Thank you Alan. But a question here, how would it understand that the given
input is valid?



The while loop makes it keep on asking until a valid input is
received. Without the while loop it would only ask once and
either return None or a digit.



On Wed, Nov 26, 2014 at 3:46 PM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> On 26/11/14 09:57, Sunil Tech wrote:
>
>> Hi Danny,
>>
>> Curious to the use the need of using while True in the given example of
>> ask_for_a_digit().
>>
>>
>> On Mon, Nov 17, 2014 at 9:57 AM, Danny Yoo <dyoo at hashcollision.org
>> <mailto:dyoo at hashcollision.org>> wrote:
>>
>>     > def ask_for_a_digit():
>>     >     while True:
>>     >         digit = raw_input("Give me a digit between 0 and 9.")
>>     >         if digit not in "0123456789":
>>     >             print "You didn't give me a digit.  Try again."
>>     >         else:
>>     >             return int(digit)
>>
>
> The while loop makes it keep on asking until a valid input is
> received. Without the while loop it would only ask once and
> either return None or a digit.
>
> HTH
> --
> 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
>
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20141126/cfea1927/attachment.html>


More information about the Tutor mailing list