Lab 3

Introduction:

In this lab, you will practice using an if-statement to determine the color of a pocket on a roulette wheel. You will also practice while loops to improve on a sales commission program.

Roulette Wheel Colors

On a roulette wheel, the pockets are numbered from 0 to 36. The colors of the pockets are as follows:

Write a program that asks the user to enter a pocket number. Display whether the pocket is green, red, or black. Display an error message if the user enters a number that is outside of the range 0 through 36.

Sales Commission Calculator

Improve the sales commission calculator from lecture (code shown below). The two improvements to make are:

  1. Use while loops to validate the sales amounts and the commission rate. The sales amount must be a positive number (or -1); if it is not valid, inform the user and ask again until it is valid. The commission rate must be a number between 0 and 1 (not including 0 or 1); if it is not valid, inform the user and ask again until it is valid.
  2. Create an accumulator variable to accumulate the total commission. After the while loop ends, display the total commission earned as a dollar amount format this to two decimal places.
#This program calculates a sales commission

#calculate a series of commissions
sales = float(input('Enter the amount of sales (or -1 to stop): '))
while sales != -1:
    comm_rate = float(input('Enter the commission rate: '))
    
    commission = sales * comm_rate
    
    print('The commission is $'+format(commission, '.2f'))
    
    sales = float(input('Enter the amount of sales (or -1 to stop): '))

Your final version of this program must still use a sentinel value to end the loop. If you want to change the sentinel value used, justify this decision in your assignment information sheet.

Question

Answer the following question on your assignment information sheet.

  1. What kinds of inputs could cause your program to crash, throw an exception/error, or not behave as the user might expect? There is at least one kind.

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 3 assignment.

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

The assignment is due Monday, June 8 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.