Intro to Computer Science
PA02
Working with Selection Statements
Code due to the Program Submission System on by 2/6 at 11:59pm
Introduction
This week we have been working with selection statements. Let's see if
you understand this idea.
Notes and requirements:
- Make sure that you save your programs in the correctly named files
- Make sure that you are following the
proper policies
regarding code based homework
- Use meaningful variable names
- Use meaningful constants and names where appropriate and use proper style
(ALL_CAPS_AND_UNDERSCORES)
- Your programs should ask for input in the exact order specified in the customer requests below.
Program 2.1 (5 points)
Create a program named overtime.py
- Accept input values for hours worked and pay rate, and calculate and return the gross pay (which will include overtime when appropriate). Assume overtime is 1.5x base pay, and the user may enter less than 40 hours (in which case, you wouldn't compute any overtime).
- Hint: How do you think about this problem? You could calculate the regular pay, and then "if" appropriate, calculate and add in the overtime.
- Hint: If you would like the money total to print out nicely, use the line of code we talked about earlier in this lesson calculating tips.
- Here is an example:
- Here is another example:
Program 2.2 (8 points)
Create a program named weather.py
- Produce code to accept a number indicating the percentage of the sky that has clouds and report a cloudiness descriptor, according to the following chart.
Percentage |
Description |
30 or less |
Clear |
between 31 and 70 |
Partly Cloudy |
between 71 and 99 |
Cloudy |
exactly 100 |
Overcast |
- Here is an example:
- Here is another example:
- Here is another example:
- Here is another example:
Program 2.3 (12 points)
Create a program named height.py
- Normal height for US females is 64 inches plus/minus 2.5 inches and for US males it is 69.5 inches plus/minus 3 inches. Accept input values indicating gender (F or M) and height and then report whether a person with those characteristics is within the average height range.
- Hint: Is 66.5 inches in the average range or not for a female person? (It is in this case, but 66.6 is not.) Be sure you test all of these "boundary cases".
- Here is an example:
- Here is another example:
- Here is another example:
Final Submission
Please submit all three programs to the Program Submission System by the due date and time.