Homework 1

Due: October 15, 2025
Points: 100

In the given examples, what you type is in redand the program prints what is in black. Your program output should look exactly like the output in the examples, except that what you type won’t be in red, and the results may differ in the last few digits.

  1. (20 points) Currently, the U.S. tax code imposes a graduated income tax with deductions and credits. Occasionally, someone will propose a “flat tax,” which charges a fixed percent of income and has no deductions or credits. The figure most often quoted is 17%. Please write a program that asks the user to enter an income as an integer (no commas or periods!) and prints the amount of tax that would be paid on that income. Reject any negative incomes or input that is not a number.

    To turn in: Please turn in the program in the file flattax.py.

    Examples:

    
    What is the income? 124598
    The tax on income of 124598 is 21181.66
    
    
    What is the income? -250
    This doesn’t work for negative incomes like -250
    
    
    What is the income?  124,598
    Error – invalid input entered; put in an integer
    
    
    What is the income? 698321
    The tax on income of 698321 is 118714.57
    

  2. (20 points) Now look at the current US tax scheme, which is a progressive tax. It works as follows:

    Reject any negative incomes or input that is not a number.

    To turn in: Please turn in the program in the file progtax.py.

    Examples:

    
    What is the income? 124598
    The tax on income of 124598 is 34846.020000000004
    
    
    What is the income? -250
    This doesn’t work for negative incomes like -250
    
    
    What is the income?  124,598
    Error – invalid input entered; put in an integer
    
    
    What is the income? 698321
    The tax on income of 698321 is 224227.52000000002
    

  3. (20 points) Write a program to calculate the volume V of a test tube given its radius r and height h using this formula:
    V = π r2 h

    Prompt the user for the radius and height, one per line. Both must be real numbers; they need not be integers.

    To turn in: Please turn in the program in the file testtube.py.

    Examples:

    
    Radius of base of cone: 1
    Height of cone: 5
    The volume of a cone with radius 1.0 and height 5.0 is 15.707963267948966
    
    
    Radius of base of cone: 2.3
    Height of cone: 3.4
    The volume of a cone with radius 2.3 and height 3.4 is 18.834895155822
    
    
    Radius of base of cone:  1/5
    Error – radius must be a real number
    
    
    Radius of base of cone:  1
    Height of cone:  3*4
    Error – height must be a real number
    

  4. (40 points) In the SI model of disease spread, i(t)> is the proportion of the population that is infected at time t and β is the average number of people each infected person spreads the disease to each day. The equation modeling the spread is:
    i(t) =
    i(0)eβt / 1 - i(0) + i(0)eβt
    where i(0) is the proportion of the population initially infected. Assume each infected person spreads the disease to 1 uninfected person every 5 days, and initially 0.1% of the population is infected. The population is constant. Write a program that takes an integer as input, and computes the proportion of the population that is infected after that many days.

    To turn in: Please turn in the program in the file si.py.

    Examples:

    
    Number of days:  30
    After 30 days, the proportion of the population infected is 0.287664368675717
    

    
    Number of days: 40
    After 40 days, the proportion of the population infected is 0.7489923252324207
    

    
    Number of days: 10.3
    You must enter an integer number of days
    


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
MHI 289I, Programming in Health Informatics
Version of October 1, 2025 at 2:22PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh