This task is part of ps02 which is due at 23:59 EDT on 2021-09-21.
You have the option to work with a partner on this task if you wish. Working with a partner requires more work to coordinate schedules, but if you work together and make sure that you are both understanding the code you write, you will make progress faster and learn more.
You can submit this task using this link.
Put all of your work for this task into the file
(you will create this file from scratch)
Armed with Python knowledge from your first CS111 lectures and lab, and confident with your debugging skills from Task 1, you've decided to form a software startup that provides your fellow students with useful programs.
Since time is important to all Wellesley students, you've decided your first program should be a time profiler that helps students calculate how they spend their time during a typical week. The program will ask the user to enter a few pieces of information, and then will display a few calculations about the time spent on various things every week:
Each time you run your program (by pressing the green triangle in Thonny) it should prompt the user to enter information about these activities and display a time profile. We have provided three example executions of the time profiling program that show how your program should behave. In each run, text in black is displayed by the program, while text highlighted in blue is entered by the user. (As in Task 1, in your actual program, the text entered by the user will also be displayed in blue.)
Note that in the example output, each number of hours has been rounded to two decimal places (in some cases Python only shows one because the second is a zero).
Also note that your program should ask the user for the name of the category used to describe the 'everything else' category, and then use that name in the remainder of the program. In the first example above, Valentina chose to use the name 'fun', Emma chose to use the label 'extracurricular', and Sofia chose to use the name 'organizing'. The user of the program gets to decide which name to use to describe that category, and your program incorporates that name into the profile.
In your account on the
cs server is the CS111 download folder
cs111/download. This folder contains a subfolder name
ps01. Begin by
ps01 folder to your computer, if you haven't already done
that for another task.
In this task, you will write a time profiling Python program
from scratch in Thonny that has the behavior indicated by the sample executions
above. You should save this file to the
Your goal is to create a
timeProfiler.py program that behaves exactly as
indicated by the sample executions provided, and
works reasonably on other sample inputs that might be used to test it.
To test by hand whether your output is correct, you can run your program, type in inputs from one of the samples provided, and then use this free difference checker website to check whether the output you got matches the sample output exactly.
However, it would be faster and less error-prone to set up some automatic
tests, which you could do using the
optimism testing library that we
went over in lab. In the future, establishing
your own tests will be required. For this task it is entirely optional,
because we expect that there is a valuable lesson about the value of
automatic tests waiting for those who may choose to "save" time by
Setting up your automatic tests before you start writing your code can be a good way to force yourself to think through the problem and gain a deeper understanding of it before you start coding.
Any output messages produced by the
optimism library won't be counted
as part of the program output, so you don't need to worry about these
messages changing the correctness of your code.
Any major programming task like this should be broken down into smaller subtasks. For this program, we can imagine simpler programs that only ask for some of the inputs, and only print some of the outputs. If we build one of those programs, we can extend it to build the full program.
For example, start by writing code to solve the subtask of prompting the user for their name and displaying the header "Weekly time profile for <name>:"
What is your name? Sofia Weekly time profile for Sofia:
Second, you could add the prompt for the number of work hours and add a corresponding line to the output display.
What is your name? Sofia How many hours do you work each week? 8.5 Weekly time profile for Sofia: 8.5 work hours
Next, add a prompt for the number of sleep hours and add a corresponding line to the output display.
What is your name? Sofia How many hours do you work each week? 8.5 How many hours per day do you sleep on average? 6.55 Weekly time profile for Sofia: 8.5 work hours 45.85 sleep hours
Continue in this way until you have prompts for all inputs and are able to produce the complete correct output. Your program should be able to reproduce the sample executions for Valentina, Emma, and Sofia. We will check the text with some flexibility in case of typos, but will also check the last four lines closely. As an extra goal, we will also test using one new input that isn't one of the examples shown here.
Note that this breakdown into subtasks is just one suggestion. You can break them down any way you prefer. However, trying to write the code for the entire program without breaking it down is a bad idea.
timeProfiler.py file must start with a documentation string
at the top, identifying the authors, people consulted, date, and
purpose of the file. Follow this format (but fill in your own info):
""" Authors: Peter Mawhorter Consulted: Lyn Turbak Date: 2021-9-14 Purpose: The time profiler task: based on answers to questions about how you spend your time, report on a weekly time budget. """
+(string concatenation) and
str. These are all explained in the Lecture 02 slides, and the links in the previous sentence take you to our quick-reference documentation.
Your program should not use any other Python features that we have not
studied yet, such as string methods, conditionals (i.e.,
lists, loops, or recursion.
For a completely correct solution, things like spacing and the number of digits after a decimal point in a number are important. But you will receive most of the credit for solutions that are not exactly correct. In order to check whether your output is totally correct, see the section on testing above.
You may assume that inputs are sensible, and the behavior of your program for nonsensical inputs is unspecified. This means that your program can do anything if an input is nonsensical and still be considered correct. For example, if the number of classes specified is not an integer, the program could fail with an error message immediately, it could fail after reading in other inputs, it could fail after printing the first line of the output display, or it could even work correctly taking that into account, but all of these would be considered "correct" behavior, because we do not expect the number of classes taken to be fractional.
Here are inputs that are sensible:
Make sure you double-check the rubric, including the procedure requirements and the style requirements. In particular, although the style requirements are extra goals, they represent principles which, if violated, often lead to incorrect code.
Results for a fictional student named Valentina.
%run timeProfiler.pyWhat is your name? Valentina How many hours do you work each week? 0 How many hours per day do you sleep on average? 8 How many classes are you taking this semester? 5 For one class, what is the average time spent in the classroom per week? 2.5 What shall we call the 'everything else' category? fun How many hours per week do you spend on 'fun'? 15 Weekly time profile for Valentina: 0.0 work hours 56.0 sleep hours 37.5 class hours 15.0 fun hours 59.5 free hours
Results for a fictional student named Emma.
%run timeProfiler.pyWhat is your name? Emma How many hours do you work each week? 8.5 How many hours per day do you sleep on average? 6.75 How many classes are you taking this semester? 4 For one class, what is the average time spent in the classroom per week? 3.67 What shall we call the 'everything else' category? extracurricular How many hours per week do you spend on 'extracurricular'? 22.5 Weekly time profile for Emma: 8.5 work hours 47.25 sleep hours 44.04 class hours 22.5 extracurricular hours 45.71 free hours
Results for a fictional student named Sofia.
%run timeProfiler.pyWhat is your name? Sofia How many hours do you work each week? 5 How many hours per day do you sleep on average? 6.55 How many classes are you taking this semester? 4 For one class, what is the average time spent in the classroom per week? 3.2 What shall we call the 'everything else' category? organizing How many hours per week do you spend on 'organizing'? 24 Weekly time profile for Sofia: 5.0 work hours 45.85 sleep hours 38.4 class hours 24.0 organizing hours 54.75 free hours
=or by defining a parameter for a function) you must also later use that variable as part of another expression. If you need to create a variable that you won't use, it must have the name
_, but you should only do this if absolutely necessary.
inputin exactly 7 places.
floatin at least 5 places.
roundin at least once place.