CSC111 Lab 8 2015

From dftwiki3
Revision as of 13:10, 22 March 2015 by Thiebaut (talk | contribs) (Created page with "--~~~~ ---- <showafterdate after="20150325" before="20150601"> =Part 1: While Loops= ==Exercise 1: Robust Input with While== <br /> ::<source lang="python"> def getPositiveN...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

--D. Thiebaut (talk) 14:10, 22 March 2015 (EDT)


<showafterdate after="20150325" before="20150601">

Part 1: While Loops

Exercise 1: Robust Input with While


def getPositiveNumber():
    #
    # put your code here
    #


def main():

    # Part 1, Exercise 1
    x = getPositiveNumber()
    print( "getPositiveNumber() returned", x )

main()


Complete the function getPositiveNumber()" so that it asks the user for a number larger than 0, and keeps on prompting the user as long as she doesn't enter a valid number.

Below is an example of the interaction between computer and user.

Please enter a number greater than 0: -1
-1 is invalid.
Please enter a number greater than 0: -3
-3 is invalid.
Please enter a number greater than 0: 0
0 is invalid.
Please enter a number greater than 0: 20
getPositiveNumber() returned 20
>>>

</showafterdate>