Programming Project 2: Decisions

Collaboration: Solo! Work on these four programs by yourself.

Due: Monday 19-Sep by 9:00 pm

Turn in: Turn in all four files to the ISTA 130 D2L drop box named Project 2: Selection

Grading: 100 points. For specific criteria see the Grading Criteria section at the end of this file

This programming project gives you a chance to implement some Input/Process/Output algorithms as Python programs where the process step involves decision statements if, else, and elif. At the beginning of each program, include comments with the information listed here where you have filled in the correct information for the [Appropriate parts]:

# Developer: [Your name]

#

# SL: [Your SL's name here]

#

# File: [programName.py]

#

# Due: [Project Due Date and Time]

#

# Purpose: [A one-paragraph description of what the program does.]

#

The following example may be used as the beginning to the first program in a file name recordCertification.py (you need to change a few things):

# Developer: [firstNamelastName]

#

# SL: [Your SL's name here]

#

# File: recordCertification.py

#

# Due Date: 9:00 pm Monday 19-Sep-11

#

# Purpose: Determine the RIAA rating for a given number of records sold

#

Program 1

Music recording sales certificationis a system of certifying that a music recording has shipped or sold a certain number of copies, where the count varies by type (album,single, music video, etc.) and by nation or territory. Almost all countries follow variations of the RIAA certification categories, for the count levels, which are named after precious materials:

  • silver- moderate sales (half the gold count)
  • gold - high sales
  • platinum - very high (often 2x-2.5x times gold count)
  • diamond - extremely high (rare, 2x-10x platinum).

Currently, the RIAA certification criteriafor albums are:

  • 500,000 units: Gold album
  • 1,000,000 units: Platinum album
  • 2,000,000 units: Multi-Platinum album
  • 10,000,000 units: Diamond album

Write a program in the file recordCertification.pythatproceeses user input and computes which certification is appropriate. Print "No Certification" if there are fewer than 500,000 record sales.

Album Sales?49999
No Certification / Album Sales?1000000
Platinum
Album Sales?500000
Gold album / Album Sales?10000000
Diamond

Program 2A leap year is any positive integer that is evenly divisible by 4 except the last year of a century, which is a year that is evenly divisible by 100. In this case, the year must also be evenly divisible by 400. For example 2000 was a leap year, but 2100 will not be a leap year. Write a Python program in the file leapYear.pythat processes user input to generate output like any of these sample dialogsalways correctly statingif the given year is or is not a leap year.

Year? 2000
2000 is a leap year / Year? 2011
2011 is not a leap year
Year? 2400
2400 is a leap year / Year? 2012
2012 is a leap year

Program 3At a local school, the grading system computes the proper letter grade using the following plus/minus system:

PercentageGrade

97.0 courseGrade < 100.0A+

93.0 courseGrade97.0A

90.0 courseGrade < 93.0A-

87.0 courseGrade < 90.0B+

83.0 courseGrade < 87.0B

80.0 courseGrade < 83.0B-

77.0 courseGrade < 80.0C+

73.0 courseGrade < 77.0C

70.0 courseGrade < 73.0C-

67.0 courseGrade < 70.0D+

63.0 courseGrade < 67.0D

60.0 courseGrade < 63.0D-
courseGrade < 60.0F

Complete a Python program in the file letterGrade.pythat processes user input to compute and print thecorrect letter grade like any of these sample dialogs below:

Course Grade? 97.0
Letter Grade: A+ / Course Grade? 82.9
Letter Grade: B-
Course Grade? 90
Letter Grade: A- / Course Grade? 75.0
Letter Grade: C

Problem4(Not a program, but a function with a return) There has been a lot of political debate about whether or not to extend tax cuts for the rich.This has a lot to do with the percentages of taxable income (income after deductions[1]) that is owed to the IRS. Each person pays 10% of the first 10,000 of taxable income, 15% on another portion of the income, until the taxpayer has $372,950 in taxable income when the highest rate of 35% gets applied (ten years ago, the highest rate was 39.6%).

The following tax table represents the amount of money owed for the year given the taxable income for the given year for a person filing with a single status:

Write a Python function named incomeTaxin a file named taxes.py. The incomeTax function takes the taxable income as an argument and always correctly returns the tax owed for the year. The return value must reflect the IRS rules for completing tax returns according to the table above. You may assume person is filing singly. TheincomeTax function begins like this (make sure you name itincomeTax, it has one formal parameter and it returns a float rounded to two decimal places).

# Developer: [firstNamelastName]

#

# SL: [Your SL's name here]

#

# File: taxes.py

#

# Due Date: 9:00 pm Monday 19-Sep-11

#

# Purpose: Determine the amount of money a taxpayer owes the IRS for a year

# of taxable income. his table is for those filing with Single status.

#

# You can run this module to see the returned

# results for as many function calls as you wish.
#

defincomeTax(taxableIncome):

result = 0.0

iftaxableIncome <= 8350.00:

result = 0.10 * taxableIncome

# more to do . . . .

# more to do . . . .

return round(result, 2)

# end of functionincomeTax(taxableIncome):

# A few function calls

print(incomeTax(10.00)) # prints1.0

print(incomeTax(125.67)) # prints 12.57

print(incomeTax(1234566)) # prints 0.0 until you add the code to handle this

Optional: The code above can be run as program. No user input is required for this problem. You could compute many test cases by hand, write many more function calls, and then compare your answer with program output. Or you could use Rick's tests, the same ones we will use to test your incomeTax function. One of the tests is provided here where assertions show a complete test of the firsttaxbracketof 0.00 through 8350.00.

deftestTaxFirstBracket(self):

self.assertEqual(0.00,incomeTax(0))

self.assertEqual(0.10,incomeTax(1))

self.assertEqual(834.90,incomeTax(8349.00))

self.assertEqual(835.00,incomeTax(8350.00))

If you want these tests plus a complete unit test for all brackets to ensure 100% correctness for the functionincomeTax(taxableIncome):

  • Get the file TaxesTest.py into the same folder as taxes.py
  • Run TestTaxes.py as a module like your other programs (Run > Run Module F5)
  • Look at the output to see which if any of Rick's test cases found a bug in your code.
  • When you see the following output with no error messages, you will likely receive 30/30 or 100% for your functionincomeTax(taxableIncome):

......

------

Ran 6 tests in 0.105s

OK

'''

Grading Criteria 100pts total

___ / 15 Program in recordCertification.pyis correct. It always works for valid input

___ / 20 Program in leapYear.py is correct. It always works for validinput (no bad input allowed)

___ / 20 Program in letterGrade.py is correct. It always works for valid input (no bad input allowed)

___ / 30 FunctionincomeTaxin taxes.py is correct. Optional: You may use the same tests

We'll test with 20assertEqualfunction calls worth 1.5 points each

___/ 15 Style and Design

___ / 5You commented (documented) each program as requested

___/ 4You used meaningful names for all identifiers in all four programs (subjective)

___/ 6Yourdialogs from the first three programs is as requested or very close

[1] These taxable income amounts after deductions are less than the annual gross pay.