CSCI 102 - Intro to Computer Science LAB

Python Assignment: Week 05

While Loops

Quick Links: zyBook | AutoGrader | Piazza | Canvas | CS @ Mines

Home | Contact | Schedule | Assignments | Syllabus |

Week 05 Python Assignment
Due by Tuesday, September 28th, 2021
        Part A: Tally for Kids (must (1) demo during class and (2) upload to Gradescope by 11:45pm)
        Part B: Soda Sprinter (due to Gradescope by 11:45pm)


Welcome to your assignment for Week 05 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 5 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: Tally for Kids (3 points)

Introduction

To get started, open IDLE and then 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: Week5A-tally.py.

You have been tasked with helping first graders to learn basic addition though a calculation program. This calculator program should add as many values as the 1st grader gives it. You should prompt for new values to add until the student enters “quit”, which signals that the 1st grader has finished entering values. Your program should then output the number of values added, and the sum of those values. You can assume the input to your program is always valid (e.g., only positive numbers to add will be entered by the 1st grader).

Hint: use int() function after you have checked the input for the keyword quit.

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: NUMBER> .
  • 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

Enter values to add. Enter quit when done.
NUMBER> 1
NUMBER> 2
NUMBER> 3
NUMBER> quit
The addition of the 3 numbers entered is:
OUTPUT 3 numbers
OUTPUT 6 total


Example Execution #2

Enter values to add. Enter quit when done.
NUMBER> 11
NUMBER> 9
NUMBER> 2
NUMBER> 1
NUMBER> quit
The addition of the 4 numbers entered is:
OUTPUT 4 numbers
OUTPUT 23 total

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 A
        #   Week 5 - Lab A - Tally for Kids
        #   References: neighbor Payton Manning for while syntax
        #   Time: 15 minutes

Part B: Soda Sprinter (4 points)

To get started, open IDLE and then 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: Week5B-soda.py.

Blaster is the anchor burro on the Mines 4x100 relay team, and he wants to ensure that Mines defends its title as the 4x100 burro relay champions. Blaster has discovered a secret weapon to help him win the race—soda. Blaster has found that the more soda he drinks, the faster he runs in his leg of the race. Unfortunately, people don't trust him when he tries to buy soda using normal currency (a burro with money? very suspicious), so his only way to obtain more soda is to trade in some empty soda bottles for a new one (depending on how many empty soda cans it costs to purchase a new one). In addition to the empty bottles resulting from his own consumption, he sometimes finds empty bottles when wandering campus that can go towards purchasing a new soda.

It's the day before the big race, and Blaster has decided to repeatedly drink and buy sodas until he can't afford any more. What is the maximum number of sodas Blaster could drink to prepare for the race?

The first input is the number of empty soda bottles in Blaster's possession at the start of the day (he starts with only empties), followed by the number of empty soda bottles found during the day, and finally the number of empty soda bottles required to buy a new soda. Output the number of sodas that Blaster drank to prepare for the race.

Lab I/O Format

The same Lab I/O format required on Part A is also required on Part B. Please see Part A if you need a refresher.

Example Execution #1

Enter the number of empty bottles in Blaster's possession at the start of the day.
EMPTIES> 9
Enter the number of empty bottles that Blaster found during the day.
FOUND> 0
Enter the number of empty soda bottles required to buy a new soda.
COST> 3
The total number of sodas that Blaster drank is:
OUTPUT 4


Example Execution #2

Enter the number of empty bottles in Blaster's possession at the start of the day.
EMPTIES> 5
Input the amount of empties that Blaster found during the day.
FOUND> 5
Enter the number of empty soda bottles required to buy a new soda.
COST> 2
The total number of sodas that Blaster drank is:
OUTPUT 9


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:
        #   John Henke
        #   ​CSCI 102 – Section G
        #   Week 5 - Lab B - Soda Sprinter
        #   References: Instructor Christine, who helped with managing the inputs
        #   Time: 25 minutes

Submit Solutions

Follow these steps to submit your files to Gradescope.
  1. In Gradescope, go to Assignments > Week5A and upload Week5A-tally.py.
  2. In Gradescope, go to Assignments > Week5B and upload Week5B-soda.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.