Homework 2: Expressions¶
Objectives¶
- Use arithmetic operators
(
+
,-
,*
,/
,**
,//
) - Use f-strings to format output with mixed types
We are using two platforms
The first 20 pts are on Runestone. Look for the HW2.1 assignment on Runestone. Answer the questions (repeatedly if needed) until you get them all correct.
The next 30 pts are on Gradescope. There are three separate "assignments" – one for each exercise below (HW2.2, HW2.3, HW2.4). Resubmit each program until you get full credit.
Docstring and PEP 8 checks
For full credit, your Gradescope submissions must pass all formatting checks. Please read the Installing Thonny, etc. and Docstring Requirements pages for more details.
HW2.1 Concept Questions¶
Complete the "HW2.1" assignment on Runestone. It consists of 10 multiple choice questions and 5 mixed-up code exercises.
HW2.2 Monograms¶
A monogram is a graphic symbol consisting of two or more letters combined (usually your initials), printed on stationery or embroidered on clothing.
The American Sweater Company of Iona Idaho (ASCII) makes sweaters with monograms.
The management would like an easier way to determine a monogram from a customer's name.
They have asked you to write a program, named monogram.py
, that will do the work for them.
The program should accept the customer's first, middle, and last names, and output the corresponding three letters. The input and output should look exactly like this:
First name? Alfred
Middle name? Edward
Last name? Neuman
The customer Alfred Edward Neuman has ordered a sweater with the monogram AEN.
Notice there is a blank line between the input and the output.
HW2.3 Average Price¶
Your boss at Amalgamated Sales Inc. is wary of complex mathematical topics such as division. He asks you to create a program that will calculate the average price of an item given the cost for a number of them.
Write a program named average.py
that inputs the name of an item, the number of items purchased, and the total price paid per item (in that order).
The program should then calculate the average price per item, store the average in a variable, and output the average formatted to two decimal places.
Your output and input should look like this:
Enter the item name: banana
Enter the number purchased: 100
Enter the total price: 153
The average price of a(n) banana is 1.53 dollars.
The prompts and output should match this example exactly, substituting the appropriate values. Note that you must calculate the average price yourself and format it to two decimal places. The name should be a string, the number purchased should be an integer, and the total price should be an integer number of dollars.
HW2.4 Baking Cookies¶
Your family is baking cookies. Each member of the family gets the same number of cookies, as many as possible, and the extras go to Rocky, your pet raccoon. For example, if you bake 32 cookies, and there are 5 people in your family, each family member gets 6 cookies, and Rocky gets the 2 left over.
Write a program named cookies.py
that inputs the total number of cookies and the number of family members (excluding Rocky!), and outputs the number of cookies for each family member and for Rocky, according to the example below:
Enter the number of cookies: 32
Enter the number of family members: 5
Each family member gets 6 cookies, and Rocky gets 2 cookies.
Reflection (required)¶
Submit the graded survey on Canvas after completing the assignment.