Programming Exercises

P1:

Write a Python program in which the user enters either 'A', 'B', or 'C'. If 'A' is entered, the program should display the word 'Apple'; if 'B' is entered, it displays 'Banana'; and if 'C' is entered, it displays 'Coconut'.

Solution:


In [ ]:

P2:

Write a Python program in which a student enters the number of college credits earned. If the number of credits is greater than 90, 'Senior Status' is displayed; if greater than 60, 'Junior Status' is displayed; if greater than 30, 'Sophomore Status' is displayed; else, 'Freshman Status' is displayed.

Solution:


In [ ]:

P3:

Write a program that sums a series of (positive) integers entered by the user, excluding all numbers that  are greater than 100.


Solution:


In [ ]:

P4:

Write a program, in which the user can enter any number of positive and negative integer values, that displays the number of positive values entered, as well as the number of negative values.

Solution:


In [ ]:

Development

D1: Metric Conversion

Develop and test a Python program that converts pounds to grams, inches to centimeters, and kilometers to miles. The program should allow conversions both ways.


Solution:


In [ ]:

D2: Leap Years to Come

Develop and test a Python program that displays future leap years, starting with the first occurring leap year from the current year, until a final year entered by the user. (HINT: Module datetime can be used)

Solution:


In [ ]:

D3: The First-Time Home Buyer Tax Credit

Develop and test a Python program that determines if an individual qualifies for a government First-Time Home Buyer Tax Credit of $8,000. The credit was only available to those that; 
(a) bought a house that cost less than $800,000, 
(b) had a combined income of under $225,000 and 
(c) had not owned a primary residence in the last three years.

Solution:


In [ ]:

D4: Home Loan Amortization

Develop and test a Python program that calculates the monthly mortgage payments for a given loan amount, term (number of years) and range of interest rates from 3% to 18%. The fundamental formula for determining this is A/D, where A is the original loan amount, and D is the discount factor. The discount factor is calculated as;

$$ D = \left(\left(1 + r\right)^n - 1\right) / r \left(1 + r \right)^n $$
where n is the number of total payments (12 times the number of years of the loan) and r is the interest rate, expressed in decimal form (e.g., .05), divided by 12. A monthly payment table should be generated as shown below,

                                Load Amount: $350,000  Term: 30 years
                                Interest Rate          Monthly Payment
                                     3%                    1475.61
                                     4%                    1670.95
                                     5%                    1878.88
                                     6%                    2098.43
                                     .                        .
                                     .                        .
                                     18%                   5274.80

In [ ]: