Python Lab 3: The Sleeper
Due Tuesday, September 21st, by 11:45pm
Introduction
Welcome to your third set of Python labs in CSCI 101! This week, we'll have
only ONE lab, which is due before the due date/time.
You should submit this lab as a single .py file. For those NOT
in CSCI 102, check out the CSCI 102 Schedule to see
what was covered this week (if needed).
To get started, open IDLE and then create a New File via the File menu. We
suggest you immediately save this file in some directory you create that you will use to
store/manage all
your Python Labs this semester (e.g., CSCI101/PythonLabs). Save this file as
Lab3-alarm.py.
Assignment
Every school morning Mirko is woken up by the sound of his
alarm clock. Since he is a bit forgetful, quite often he leaves the alarm on and is
woken early on Saturday
morning too. That’s not too bad though, since he feels good when he realizes he
doesn’t have to get up from his warm and cozy bed.
He likes that so much, he would like to
experience that on other days of the week too! His friend Slavko offered this
simple solution: set his alarm clock 40 minutes early, and he can enjoy the
comfort of his bed, fully awake, for 40 minutes each day.
Mirko decided to heed his advice; however his
alarm clock uses 24-hour notation and he has issues with adjusting the time.
Help Mirko write a program that will take one time stamp, in 24-hour notation,
and print out a new time stamp, 40 minutes earlier, also in 24-hour notation.
If you are unfamiliar with 24-hour time notation
yourself, you might be interested to know it starts with 00:00 (midnight) and ends
with 23:59 (one minute before midnight).
Your Program
Write a program which asks the user for two integers:
- The hour of the day that Mirko needs to get out of bed.
- The minute of the day that Mirko needs to get out of bed.
You may assume that the user will only
enter positive integers for each input. Further, you may assume that the
hours will be no greater than 23, and the minutes will be no greater than 59.
Then, your program should determine when
Mirko needs to set his alarm and output the time (hours, then minutes,
seperated by a space) on a single line.
Hint: You can use f-string formatting to pad with leading zeroes
when necessary.
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: HOURS>
and MINUTES> .
- 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:
HOURS> 10
MINUTES> 10
OUTPUT 09 30
Example Execution 2:
HOURS> 0
MINUTES> 30
OUTPUT 23 50
Example Execution 3:
HOURS> 23
MINUTES> 45
OUTPUT 23 05
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. 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 D
# Python Lab 3
# References: no one
# Time: 25 minutes
Submission
Once you are satisfied with your solution to this lab, you need to
submit the file to Gradescope. In Gradescope, go to Assignments > Lab3
and upload Lab3-alarm.py.
Note: this lab is worth 6 points. To receive credit, your code must execute in Python 3,
you must submit a single file (your Python code file), and you
must have the input/output 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.
NOTE: This problem was derived from a problem from the Croatian Open Competition in Informatics
2009/2010, contest #7. License is for educational use only.
|