Difference between revisions of "CSC111 Lab 9 2015"
(Created page with "--~~~~ ---- <showafterdate after="20150401 12:00" before="20150601 00:00"> <br /> =Exceptions= <br /> ==preparation== <br /> * Create a new program called lab9_1.py, and copy...") |
|||
Line 2: | Line 2: | ||
---- | ---- | ||
− | <showafterdate after="20150401 12:00" before="20150601 00:00"> | + | <!--showafterdate after="20150401 12:00" before="20150601 00:00"--> |
<br /> | <br /> | ||
=Exceptions= | =Exceptions= | ||
Line 34: | Line 34: | ||
− | </showafterdate> | + | <!-- /showafterdate --> |
Revision as of 07:15, 29 March 2015
--D. Thiebaut (talk) 07:14, 29 March 2015 (EDT)
Exceptions
preparation
- Create a new program called lab9_1.py, and copy this code to the new Idle window.
# getInput: returns an integer larger
# than 0. Expected to be robust
def getInput():
x = int( input( "Enter an integer larger than 0: " ) )
while x <= 0:
x = int( input( "Invalid number: Please try again: " ) )
return x
def main():
num = getInput()
print( "You have entered", num )
main()
- Test it with numbers such as -3, -10, 0, 5. Verify that the input function works well when you enter numbers.
- Test your program again, and this time enter expressions such as "6.3", or "hello" (without the quotes).
- Make a note of the Error reported by Python: