Week 04 Python Assignment
Due by Tuesday, September 21st, 2021
Part A: Receipt Generator (must (1) demo during class (2) upload to Gradescope by 11:45pm)
Part B: Amino Acids (due to Gradescope by 11:45pm)
Welcome to your assignment for Week 04 of CSCI 102! Each week, you will typically have multiple homework assignments (labs).
These labs are to be done on your own (not pair programming), with one lab to be demoed in class Tuesday.
All labs (including the demo labs) need to be submitted to Gradescope by 11:45pm on the due date.
Unlike CSCI 101, we will place all assignments for a
given week on one HTML page. This is your Week 4 CSCI 102 Assignment page.
You have TWO problems to do this week, the first of which (Part A) you will
demo in class with a TA on Tuesday. Details on Part A and Part B are below.
Part A: Receipt Generator (3 points)
Introduction
To get started, open IDLE and create a New File via the File menu. We
suggest you immediately save this file in the CSCI102 directory managing all
your Python Labs this semester. Please save this file with the following name:
Week4-receipt_generator.py.
Assignment
Most businesses use a sales receipt (i.e., a physical slip of paper
generated by a cash register or sent via email in online sales) to
keep record of all sales made each day. Customers also rely on receipts to
confirm their purchase amount and return (or exchange) items purchased in the future.
The purpose of this lab is to write a program that generates a receipt for three products purchased (and entered) by the user.
(In today's world, items purchased are typically scanned with a bar code scanner instead of being
typed by a human; prior to scanners though, items had to be typed!)
Your program should comply with the following algorithm.
- Ask the user for their company name, city/state, cashier name, and favorite thank-you message. Store the values entered as
variables.
- Ask the user to enter three product/items they would like to purchase (name followed by the price). Store
the values entered as variables with appropriate names. You may assume that the user will only enter a positive amount of dollars.
- Follow the format in the sample execution to print/display the receipt to the console.
- Calculate the total cost and round up to two decimal digits.
- HINT: You can use an f-string format, i.e., f"{decimal_variable:.2f}",
to display the number of digits after the decimal place.
Example Execution
Enter company name: The Real Mines Market
Enter company city/state: Golden, Colorado
Enter cashier name: Blaster
Purchased item 1 name: Tear Catcher
Purchased item 1 price: 12.99
Purchased item 2 name: Laminated NB
Purchased item 2 price: 4.97
Purchased item 3 name: Smart Cookie
Purchased item 3 price: 1.03
Enter your favorite ending message: Thank you! Go Orediggers!
Example Output
RECEIPT GENERATOR
-----------------------------------
The Real Mines Market
Golden, Colorado
===================================
Your cashier was: Blaster
Welcome Valued Customer
===================================
Item Name Item Price
Tear Catcher $12.99
Laminated NB $4.97
Smart Cookie $1.03
===================================
Total Cost of Order: 18.99
===================================
Thank you! Go Orediggers!
-----------------------------------
Gradescope Submission Nuances
You will demo this lab in class on Tuesday and should also submit it to Gradescope after demoing in class.
Because this is a demo lab, no tests will be run upon submission to Gradescope—your grade will be based on your performance in the demo.
Comments
All Python files should include a header with your name,
section, assignment info, references (i.e., who did you collaborate
with on this assignment?; what resource did you use?), and approximate
time taken to do the assignment. Be sure to cite
any allowed external references used to complete the
assignment. Any code without this header will lose 1
point. Here's an example:
# Tracy Camp
# CSCI 102 – Section C
# Week 4 - Lab A - Receipt Generator
# References: Friend Billie Joe Armstrong, who helped me with how to print two decimal points
# Time: 25 minutes
Part B: Amino Acids (4 points)
Introduction
To get started, open IDLE and create a New File via the File menu. We
suggest you immediately save this file in the directory managing all
your 102 Python Labs this semester. Please save this file with the following name:
Week4B-amino_acids.py.
In this lab, you will determine one of six amino acids based on the elements that compose its chain.
Here is a table that shows the six amino acids you will distinguish between, and the elements
in their chemical formula:
Carbon (C), Hydrogen (H), Nitrogen (N), Oxygen (O), and Sulfur (S).
Amino Acid |
C |
H |
N |
O |
S |
Alanine - plays a key role in glucose |
3 |
7 |
1 |
2 |
0 |
Arginine - enhanced immunity, boost your arginine with pumpkin seeds |
6 |
14 |
4 |
2 |
0 |
Asparagine - first discovered in asparagus, non-essential amino acid in humans |
4 |
8 |
2 |
3 |
0 |
Cysteine - semi-essential amino acid that is found in hog hair |
3 |
7 |
1 |
2 |
1 |
Histidine - important for children, as may help immune system |
6 |
9 |
3 |
2 |
0 |
Glutamine - important amino acid for bodybuilders |
5 |
10 |
2 |
3 |
0 |
You can assume the input to your program is always valid (e.g., oxygen input will only be 2 or 3 in this case).
The output of your program should be the Amino Acid that matches the input information.
For efficiency, your solution must use nested if statements. We strongly encourage you to write
out pseudocode for your algorithm before you start to type Python code. Perhaps your algorithm might be:
- Prompt the user for the number of elements.
- Determine which amino acid matches. (You should extend here. How is it best to do this?)
- Create the chemical formula string for the amino acid.
- Output the amino acid name and its chemical formula string to the user.
Lab I/O Format
For lab assignments this semester, a specific Lab
Input/Output Format is required. This format
is described below:
- When prompting for input, use the prompt string
WORD> , where WORD
is a single, uppercase word which describes the input. For
example, this lab might choose: CARBON>
and HYDROGEN> , etc.
- When providing output that will be graded, start the line
with the word
OUTPUT followed by exactly one space, e.g. OUTPUT .
Think of this as "boxing your answer" on a math worksheet; it lets us quickly
find your answer. Gradescope will skip any output
lines that do not start with OUTPUT .
- You are welcome to have other output lines that do not
begin with OUTPUT; Gradescope
will ignore these.
- A submission without exactly correct output formatting will receive an AUTOMATIC ZERO.
This is because Gradescope is automated—it does not look at your code, only the results, and thus
the format of the results must be consistent for all students.
Example Execution
Input the chemical elements of the amino acid:
CARBON>5
HYDROGEN>10
NITROGEN>2
OXYGEN>3
SULFUR>0
The amino acid for 5C--10H--2N--3O--0S is Glutamine
OUTPUT 5C--10H--2N--3O--0S
OUTPUT Glutamine
Gradescope Submission Nuances
Part B will ONLY be submitted to Gradescope (you will NOT demo this lab in class).
When you submit your Python file to Gradescope, multiple different test
cases are run on your code. Passing all of the tests results in a 100% on
the autograded portion of the lab. You are allowed to submit to Gradescope four
times (or less) for this lab. The maximum grade of your submissions will be your grade for
the lab. Note: If your code doesn’t work (e.g., a syntax error exists,
or an error is thrown in execution), then you will received an AUTOMATIC ZERO. You
should test your code before submitting to ensure it executes correctly.
Comments
All Python files should include a header with your name,
section, assignment info, references (i.e., who did you collaborate
with on this assignment?; what resource did you use?), and approximate
time taken to do the assignment. . Be sure to cite
any allowed external references used to complete the
assignment. Any code without this header will lose 1
point. Here's an example:
# Tracy Camp
# CSCI 101 – Section H
# Week 4 - Lab B - Amino Acids
# References: TA Cole for runtime debugging help
# Time: 60 minutes
Submit Solutions
Follow these steps
to submit your files to Gradescope.
- In Gradescope, go to Assignments > Week4A and
upload Week4A-receipt_generator.py.
- In Gradescope, go to Assignments > Week4B and
upload Week4B-amino_acids.py.
To receive credit, your code must execute in
Python 3, and you must submit a single file for each
portion of the assignment (your Python code file).
In addition, your code must follow the Lab I/O
Format.
Whenever you submit something to Gradescope, we
strongly recommend you always double check what
you submitted actually got submitted correctly
(e.g., did the file upload correctly? did you
submit the correct file? etc.) If your submission
is incorrect, it's on you.
|