[Tutor] Question about conditions and empty values

Shelby Martin shelby.martin at gmail.com
Mon Oct 28 16:59:26 CET 2013


I use the Python GUI called IDLE. As far as I can tell, it doesn't show me
any error messages, but when the program shuts down suddenly due to a
coding error, some sort of text pops up very briefly on the screen before
it shuts down. Sorry, I'm a complete newbie to Python :) And thanks for
your help.


On Sat, Oct 26, 2013 at 4:45 PM, Alan Gauld <alan.gauld at btinternet.com>wrote:

> On 26/10/13 20:13, Shelby Martin wrote:
>
>  My question is this - the author of this exercise states the condition
>> is False if either zero or "empty" is the value. I'm assuming he means
>> that empty is just pressing Enter without entering a number?
>>
>
> Normally that would be correct but...
>
>
>
>> money = int(input("How many dollars do you slip the Maitre D'?"))
>>
>
> Here we try to convert the string to an int. and int() fails
> when given an empty string so your program never reaches the
> if test.
>
> Which begs the question: GHOw are you running your programs?
> If you used a console or an IDE it should have shown you the error message
> which would have explained what and where things went wrong.
>
> You would need to either use a try/except clause around the conversion or
> check for an empty string before converting. try/except is the preferred
> route but you may not have covered that yet.
>
>
>  if money:
>>      print("Ah, I am reminded of a table. Right this way.")
>> else:
>>      print("Please, sit. It may be a while.")
>>
>
> If you did get the error message then please, in future, include
> any such in their entirety in posts because they greatly simplify
> diagnosing more complex issues.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/**alangauldphotos<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<https://mail.python.org/mailman/listinfo/tutor>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131028/1b79192f/attachment.html>


More information about the Tutor mailing list