Always. :-)
Actually we'd like to write a program which will suggest whether or not we can sleep in. Our criteria will be as follows.
Let's write a program to input the day of the week and ask whether or not its a holiday, then make the appropriate decision as to whether or not we should sleep in.
We will use the Write - Refactor - Test - Rewrite approach to complete the final solution which will refactor the day of the week logic into a function.
Here's the algorithm of this program. Write the solution in Python.
input day of the week
input is it a holiday
if day of the week is a weekend
print go back to bed its the weekend
else
if its a holiday
print go back to bed. its a holiday
else
print you need to get up
Example Run 1:
What day of the week is it? Monday
Is it a holiday? No
You need to get up!
Example Run 2:
What day of the week is it? Saturday
Is it a holiday? No
Go back to bed! It's the weekend.
Example Run 3:
What day of the week is it? Monday
Is it a holiday? Yes
Go back to bed! It's a Holiday.
In [1]:
## TODO: Write the solution here
In [7]:
## Step 2: Refactor into function IsWeekend(day_of_week)
Time to test. Write 7 tests, once for each day of the week.
WHEN day_of_week='Monday' We EXPECT IsWeekend(day_of_week) to return False
WHEN day_of_week='Tuesday' We EXPECT IsWeekend(day_of_week) to return False
WHEN day_of_week='Wednesday' We EXPECT IsWeekend(day_of_week) to return False
WHEN day_of_week='Thursday' We EXPECT IsWeekend(day_of_week) to return False
WHEN day_of_week='Friday' We EXPECT IsWeekend(day_of_week) to return False
WHEN day_of_week='Saturday' We EXPECT IsWeekend(day_of_week) to return True
WHEN day_of_week='Sunday' We EXPECT IsWeekend(day_of_week) to return True
In [2]:
# Step 3: Write tests. Similar to how we did it in the lab.
In [1]:
## Step 4: Write program here from the algorithm above
IsWeekend
?Answer:
Answer:
Answer:
'sat'
for 'Saturday'
Does it work? How can the program be improved? Does improving it affect the readability of step 4? (HINT: Abstractions!!!)Answer:
Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?
To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.
Keep your response to between 100 and 250 words.
--== Write Your Reflection Below Here ==--