Extra Credit 1

Due: October 14, 2024
Points: 34


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. Also, the symbol “↵” is a newline (return or enter keys).

  1. (10 points) Change your solution to problem 3 in homework 1 as follows. On each line, print the difference between the value computed and the value of π.

    To turn in: Please turn in the program in the file pi-ex.py.

    Sample output: only the first 4 lines are shown

     100000	3.141582653589720	0.000010000000073
     200000	3.141587653589762	0.000005000000031
     300000	3.141589320256464	0.000003333333329
     400000	3.141590153589744	0.000002500000049
    
  2. (24 points) In the make_change.py program, change the output to reflect the following:
    1. If there is exactly 1 quarter, dime, nickel, or penny, your output uses the singular for the coin
    2. If there is more than 1 quarter, dime, nickel, or penny, your output uses the plural for the coin
    3. If there are no quarters, dimes, nickels, or pennies, do not print that coin
    4. If a non-positive integer, or a non-integer, is entered, give the error message “bad input; must be a positive integer” and quit
    5. If there are two different types of coins, put an “and” between them
    6. If there are three or more types of coins, put a comma after each type of coin except the last, and put an “and” between the last two types of coins.

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

    Examples:

    Amount of change: 92
    92 cents is 3 quarters, 1 dime, 1 nickel, and 2 pennies
    
    Amount of change: 16
    16 cents is 1 dime, 1 nickel, and 1 penny
    
    Amount of change: 15
    15 cents is 1 dime and 1 nickel
    
    Amount of change: 30
    30 cents is 1 quarter and 1 nickel
    
    Amount of change: 34
    34 cents is 1 quarter, 1 nickel, and 4 pennies
    
    Amount of change: 1
    1 cent is 1 penny
    

UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
ECS 235A, Computer and Information Security
Version of September 24, 2024 at 10:32AM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh