Homework 1

Due: October 6, 2021
Points: 100


In the given examples, what you type is in red and 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.

  1. (20 points) There are 16 ounces in a pound, and 2.2046226218488 pounds to the kilogram.

    Write a program that prompts the user for a weight in pounds and converts it to ounces and kilograms. The temperature may be an integer or a real number. Round the temperatures to two places in the output.

    Assume the input is valid; that is, the user will enter a real number.

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

    Hint: Use the function round(x, 2) to round x to two places. For example, say round(2.3456, 2) to round 2.3456 to two places.

    Examples:

    
    Enter weight in pounds: 1
    1.0 pounds is 16.0 ounces and 0.45 kilograms
    

    
    Enter weight in pounds: 435
    435.0 pounds is 6960.0 ounces and 197.31 kilograms
    

    
    Enter weight in pounds: 1237
    1237.0 pounds is 19792.0 ounces and 561.09 kilograms
    

  2. (20 points) Write a program that reads in a positive integer and prints the sum of all multiples of 3 and 5 less than or equal to the number entered.

    Assume that the input is valid; that is, the user will enter a positive integer.

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

    Examples:

    
    Enter number: 16
    The sum of multiples of 3 and 5 less than or equal to 16 is 60
    
    
    Enter number: 10
    The sum of multiples of 3 and 5 less than or equal to 10 is 33
    

    
    Enter number: 102
    The sum of multiples of 3 and 5 less than or equal to 102 is 2520
    

    
    Enter number: 1000
    The sum of multiples of 3 and 5 less than or equal to 1000 is 234168
    

  3. (30 points) A company is adding some features to its cars. It is producing these units itself, and so wants to minimize the expense. They have figured out that the cost of producing x units is x3 − 7x + 432 dollars. They want to know when the cost is minimized.

    Write a program that iterates through the number of units, beginning with 0, and stop when the cost of the number of units is greater than the cost of the previous number of units. Print the number of units, and the cost, until this happens.

    Note the number of units must be a whole, nonnegative number; no fractional units allowed!

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

    Examples:

    
    The cost of producing 0 units is $ 432
    The cost of producing 1 units is $ 426
    

  4. (30 points) A paper proposed the following equation for the cumulative deaths for COVID-19 after x days, where x ≥ 30:
    9×10−9x6 − 6×10−6x5 + 0.0015x4 − 0.1376x3 + 7.4558x2 − 97.284x
    Write a program that reads an integer number of days and prints the cumulative deaths. If the number of days is less than 18, reject the input. Round the number of deaths to the nearest integer.

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

    Examples:

    
    Number of days: 150
    After 150 days, the number of deaths predicted is 95029
    

    
    Number of days: 30
    After 30 days, the number of deaths predicted is 1152
    

    
    Number of days: 8
    The number of days must be at least 18
    


Footnotes

  1. H. Kumar, P. Arora, M. Pant, A. Kumar, and S. Khan, “A simple mathematical model to predict and validate the spread of Covid-19 in India,” Materials Today: Proceedings of the Third International Conference on Computational and Experimental Methods in Mechanical Engineering, 47(13) pp. 3859–3864 (2021). DOI: 10.1016/j.matpr.2021.03.434

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 September 22, 2022 at 11:33PM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh