Week 02 Python Assignment
Due by Tuesday, September 7th, 2021
Part A: Simple Calculator (must (1) demo during class (2) upload to Gradescope by 11:45pm)
Part B: List Slicing (due to Gradescope by 11:45pm)
Welcome to your assignment for Week 02 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 2 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: Simple Calculator (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 directory managing all
your Python Labs this semester. Please save this file with the following name:
Week2A-simple_calculator.py.
The purpose of this lab is to create a program that prints the results of basic
math operations, specifically addition, subtraction, multiplication, and division. Each result should be
printed with ONE decimal point, except for the quotient (which should have zero decimal points) and the remainder (which should have two).
We recommend using f-strings with, for example, remainder:.2f (to print two decimal places for the reminder).
For your Simple Calculator, we recommend the following steps:
- Declare operand_one and operand_two variables, initializing each to 0.0.
- Declare the variables sum, difference, quotient, product, and remainder, and initialize each to 0.0.
- Prompt the user to input a real number as the first operand, assigning it to your operand_one variable.
- Prompt the user to input a real number as the second operand, assigning it to your operand_two variable.
- Calculate the sum of the two operands, assigning it to your sum variable.
- Calculate the difference, quotient, product, and remainder of the two operands, assigning each to the respective variable you've declared.
- Output the result of each calculation, with the number of decimal points required.
Hint: For division, use operand_one as the dividend and operand_two as the divisor.
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: FIRST>
and SECOND> .
- 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 #1
Input the first operand.
FIRST> 27
Input the second operand.
SECOND> 12
The sum of 27.0 and 12.0 is 39.0
OUTPUT 39.0
The difference of 27.0 and 12.0 is 15.0
OUTPUT 15.0
The product of 27.0 and 12.0 is 324.0
OUTPUT 324.0
The quotient of 27.0 and 12.0 is 2
OUTPUT 2
The remainder of 27.0 and 12.0 is 3.00
OUTPUT 3.00
Example Execution #2
Input the first operand.
FIRST> 6.75
Input the second operand.
SECOND> 3
The sum of 6.75 and 3.0 is 9.8
OUTPUT 9.8
The difference of 6.75 and 3.0 is 3.8
OUTPUT 3.8
The product of 6.75 and 3.0 is 20.2
OUTPUT 20.2
The quotient of 6.75 and 3.0 is 2
OUTPUT 2
The remainder of 6.75 and 3.0 is 0.75
OUTPUT 0.75
Example Execution #3
Input the first operand.
FIRST> 0.3333
Input the second operand.
SECOND> 5.2
The sum of 0.3333 and 5.2 is 5.5
OUTPUT 5.5
The difference of 0.3333 and 5.2 is -4.9
OUTPUT -4.9
The product of 0.3333 and 5.2 is 1.7
OUTPUT 1.7
The quotient of 0.3333 and 5.2 is 0
OUTPUT 0
The remainder of 0.3333 and 5.2 is 0.33
OUTPUT 0.33
Gradescope Submission Nuances
You will demo this lab in class on Tuesday, September 7th 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. However,
proper I/O formatting is still required.
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 G
# Week 2 - Lab A - Simple Calculator
# References: TA Patrick showed me how to do the remainder
# Time: 30 minutes
Part B: List Slicing (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 directory managing all
your Python Labs this semester. Please save this file with the following name:
Week2B-list_slicing.py.
The purpose of this lab is to gain practice with list slicing. Load up your Python Interpreter (your IDLE program) and
write a new program that:
- Asks the user to input a string
- Saves the string by assigning the input to a string variable, e.g., the_str
- Asks the user to input four numbers: a, b, c, and d
- Prints the slice (or piece) of the string from indices a through b and c through d, NOT inclusively (i.e. not
including the characters at indices a, b, c, and d, but rather only the characters between indices a, b, c, and d)
Lab I/O Format
The same I/O Format on Part A is required on Part B. Please see the Lab I/O
formatting specifications in Part A if you need a refresher.
Example Execution
Enter your string:
STRING> HumptyDumptysatonawallHumptyDumptyhadagreatfall
Enter four numbers to slice the string
A> 21
B> 28
C> 5
D> 12
OUTPUT Humpty Dumpty
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 102 – Section E
# Week 2 - Lab B - List Slicing
# References: Instructor Christine showed me how to slice a list
# Time: 25 minutes
Submit Solutions
Follow these steps
to submit your files to Gradescope.
- In Gradescope, go to Assignments > Week2A and
upload Week2A-simple_calculator.py.
- In Gradescope, go to Assignments > Week2B and
upload Week2B-list_slicing.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.
|