Lab 6

Introduction:

In this lab, you will practice exception handling and writing functions.

Exception Handling

You will write two short programs:

  1. Searching for a favorite thing: complete this program to search for the user's input and display the location or that the item was not found (lab06_favorite_things.py. More instructions are in the source code file.
  2. Ask the user for a positive integer. If the user does not enter an integer, ask repeatedly until they do. Once they enter a positive integer, display the factorial of that number. Use exception handling to verify the user's input and the factorial function (provided by the math module) to compute the factorial.

Function

The input function takes a string and returns whatever the user entered (as a string). Write a function called input_float that takes a string (the prompt to display to the user) and return the user's response as a float. If the user does not enter a float, display an error message and ask again. Continue asking until the user enters a float. Use exception handling to check whether it is a float. If the programmer using your function passes into the function "Please enter a float: ", the user of that program should see:

Please enter a float: cat
You must enter a float.
Please enter a float: dog
You must enter a float.
Please enter a float: 13

Submission and Grading:

Complete the Assignment Information Sheet.

Submit your final program and assignment information sheet (zipped into one file) to CourseWeb in the Lab 6 assignment.

The grading rubric can be found here: Rubric (doc).

The assignment is due Monday, July 6 by 11:30 am. As with all programming assignments, you have unlimited uploads (before the deadline), so you may upload the assignment before the deadline. If you later decide to upload another, you may do so without penalty (as long as it's before the assignment deadline). The last submission uploaded before the deadline will be the one graded. If you would like ungraded feedback on a programming assignment, you may send an email to your TA or the instructor and ask for feedback; please send your code as well.

For more advice on submitting your assignment, see the Programming Assignments section of the Tips for Success page.