Re: [Tutor] Question about conditions and empty values

2013-10-28 Thread Alan Gauld

On 28/10/13 15:59, Shelby Martin wrote:

I use the Python GUI called IDLE. As far as I can tell, it doesn't show
me any error messages,


How are you running the program in IDLE?
When I type the code into a new edit window, save it and run it from 
within IDLE the error trace appears in the Python Shell window of IDLE.


Are you not seeing that?


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about conditions and empty values

2013-10-28 Thread Shelby Martin
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 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
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/**mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Question about conditions and empty values

2013-10-26 Thread Alan Gauld

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

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor