Instructions for timeProfiler

(produced at 00:07 a.m. UTC on 2021-09-15)

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 timeProfiler.py
(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:

  1. Classwork: This includes time in class plus homework time. You should assume that two hours of homework time are required for every hour in class.
  2. Work: This is time spent working for pay.
  3. Extra Activities: This includes time spent in organized athletics, music activities, clubs and any other extracurricular activities. Your program will ask the user to name this category.
  4. Sleep: This is the amount of time you spend sleeping each week.
  5. Free Time: For simplicity, this category encompasses all activities not covered by the other three activities above.

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 copying this 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 timeProfiler.py from scratch in Thonny that has the behavior indicated by the sample executions above. You should save this file to the ps01 folder.

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.

Testing

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 skipping them.

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.

Incremental Development

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>:"

Sample Execution for Subtask 1

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.

Sample Execution for Subtask 2

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.

Sample Execution for Subtask 3

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.

Notes

  • Your 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.
    """
    

  • Your program should only use Python features presented by the end of Lab 01, and Lecture 02. In particular, your program can use:

    • The arithmetic operators +, -, and *;
    • The string operators + (string concatenation) and * (string repetition);
    • The built-in functions float, int, len, max, print, input, round, 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., if statements), 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:

    • The name input may be any string, including the empty string.
    • The number of classes is assumed to be an integer.
    • The average time in class per week is expected to be a number (integer or floating point number)
    • The number of extracurricular hours per week is expected to be a number (integer or floating point number)
    • The number of hours slept per day is expected to be a number (integer or floating point number)
    • The number of inputted hours or their total sum will not be larger than the total number of hours in a week (168 hours). This would lead to a negative value for the amount of free hours.
    • The 'everything else' category can be any string that is not one of the other category names (i.e, it will not be "work", "sleep", "class", or "free").
  • 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.

Examples

Valentina example

Results for a fictional student named Valentina.

In []:
%run timeProfiler.py
Prints
What 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

Emma example

Results for a fictional student named Emma.

In []:
%run timeProfiler.py
Prints
What 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

Sofia example

Results for a fictional student named Sofia.

In []:
%run timeProfiler.py
Prints
What 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

Rubric

 
unknown Style Requirements
How your code is written.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown Do not ignore the results of any fruitful function calls
According to the "Don't waste fruit" principle, every place you call a fruitful function (built-in or custom) you must store the result in a variable, or that function call must be part of a larger expression that uses its return value.
 
unknown Do not create any variables that you never make use of
According to the "Don't waste boxes" principle, every time you create a variable (using = 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.
 
unknown Procedure Requirements
What code you use to solve the problem.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown Call input
Call input in exactly 7 places.
 
unknown Call int
Call int or float in at least 5 places.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown Call round
Call round in at least once place.
 
unknown Behavior Requirements
What your code does from the user's perspective.
 
unknown Core goals
Complete all core goals for core credit. Get partial credit for completing at least half, and more partial credit for completing at least 90%.
 
unknown Output from running your file is approximately correct (Valentina input)
We will test what is printed by your code, given the example input for 'Valentina'.
 
unknown Reported time values are correct (Valentina input)
We will check that the output lines which start with numbers closely match the correct output, for the 'Valentina' example.
 
unknown Output from running your file is approximately correct (Emma input)
We will test what is printed by your code, given the example input for 'Emma'.
 
unknown Reported time values are correct (Emma input)
We will check that the output lines which start with numbers closely match the correct output, for the 'Emma' example.
 
unknown Output from running your file is approximately correct (Sofia input)
We will test what is printed by your code, given the example input for 'Sofia'.
 
unknown Reported time values are correct (Sofia input)
We will check that the output lines which start with numbers closely match the correct output, for the 'Sofia' example.
 
unknown Extra goals
Complete all extra goals in addition to the core goals for a perfect score.
 
unknown Output from running your file is exactly correct (extra input)
We will test what is printed by your code, given some new inputs.