Python Lab EC: The Golden Sum
Due Tuesday, November 30th, by 11:45pm
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 you created to manage all your
Python Labs this semester (e.g., CSCI101/PythonLabs). Save this file as
LabEC-sum.py.
Introduction
Every E-days, Mines hosts a game show, The Golden Sum! The game consists of multiple rounds and tests
the ability of each contestant to perform mental math. In each round, contestants are provided with n cards where
each card has a single or multi-digit number on it. The announcer then supplies a number, g. The first contestant to
select and hold up two of their cards that add up to the given number g wins the round. The contestant that wins the
most rounds wins the game and free VIP tickets to the E-days concert for them and up to 5 friends!
To make the game more interesting, the cards are printed in the following font:
Some cards can be flipped upside down to display different numbers. For example, a card with 66 flipped upside down
now shows 99. It is legal to flip either or both of the cards used to generate the sum g. However, note that some
cards cannot be flipped upside down because some of the numbers on the cards would no longer be valid number
characters in the font above.
You and your friends have concocted a devious plan to win the game. While you are competing, your friends will solve
the round using a previously written Python program and tell you the answer telepathically (you’ve invented telepathy,
but still need these front row seats so obviously you need to win the game).
Note: As this is an extra credit assignment meant to showcase your Python skills, assistance given by instructors
and mentors in office hours may be limited to simple syntax and debugging fixes, not overall structure of this code.
Input
Input will be a file with the name "cards.csv". You can assume this file will be available for your program to use.
As in previous labs, you must use a relative path and not an absolute path to open the file.
The first line of cards.csv contains the number of cards, 1 ≤ n ≤ 1000 and the desired sum 2 ≤ g ≤ 200,000
The second line of cards.csv contains n comma-separated integers where the value of each integer is between 1 and 100,000 inclusive. Your program should
not accept any arguments from stdin (aka the input() function).
Output
If it is possible to generate the sum by adding two of the cards, output (to stdout, aka print) “OUTPUT Possible”. It is likely that there are multiple
possible pairs which add to the sum. Output the pair which uses the smallest number of all possible pairs in this case, with the
smaller number of the pair first.
If it is not possible to generate the sum, then output “OUTPUT Not Possible” followed by
"OUTPUT 0 0" on the following line.
Additional Requirements
You MUST write a function called "get_representation" which (1) takes a single integer argument and (2) returns the
integer value of that number flipped upside down according to the font above, if it is possible to flip that
number upside down. If it is not possible to flip the given number upside down, then the function must return zero.
You will not receive credit for this function if the name does not match the name given above.
Lab I/O Format
Throughout this semester we use a specific Lab Input/Output Format.
This format is described below:
- When providing output that will be graded, start the line with
OUTPUT . Think of this as "boxing your
answer" on a math worksheet; it lets us quickly find your
answer. Our grading script will skip any output lines that do
not start with OUTPUT .
- You are welcome (and should!) have other output lines that do
not begin with OUTPUT; while our grading
script will ignore these, good programmers include print
statements that are informational to the user of the program.
- 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 (Contents of cards.csv)
5,10
5,1,6,11,4
Program Execution:
OUTPUT Possible
OUTPUT 1 9
Example Execution 2:
Input (Contents of cards.csv)
3,27
15,21,22
Program Execution:
OUTPUT Possible
OUTPUT 12 15
Example Execution 3:
Input (Contents of cards.csv)
8,25
12,3,5,78,50,100000,99,2
Program Execution:
OUTPUT Not Possible
OUTPUT 0 0
Gradescope Submission Nuances
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.
Please IGNORE the automated email from Gradescope, this information is incorrect.
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 receive 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 101 – Section F
# Python Lab EC
# References: TA Gabe for pseudocode help
# Time: 45 minutes
Submission
Once you are satisfied with your solution to this lab, you need to submit the file to
Gradescope. In Gradescope, go to CSCI 101 > LabEC and upload LabEC-sum.py.
Note: this lab is worth 10 points of extra credit. To receive credit, your
code must execute in Python 3, and you must
submit a single file (your Python code file). In addition, your
input/output must match the lab requirements.
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.
|