Skip to content

What time is it?

Sar Champagne Bielert edited this page Apr 5, 2024 · 7 revisions

Unit 1 Session A

U-nderstand

Understand what the interviewer is asking for by using test cases and questions about the problem.

  • Will the input always be an integer?
    • Yes.
  • Should the function print anything out?
    • No, it should return the answer as a string.

P-lan

Plan the solution with appropriate visualizations and pseudocode.

General Idea: Return "adult" if the provided number is over 18, and "child" otherwise.

1) Set up the function:
  a) Create a new function with a parameter representing the hour
  b) If it's taco time, return the appropriate string
  c) If it's peanut butter jelly time, return the appropriate string
  d) Otherwise, it must be nap time!  Return the appropriate string
2) Test the function for all possible results by:
  a) Calling the function and saving the result to a variable
  b) Printing out the result.

I-mplement

def what_time_is_it(hour):
	if hour == 2:
		return "taco time"
	elif hour == 12:
		return "peanut butter jelly time"
	else:
		return "nap time"

time = what_time_is_it(2)
print(time)
time = what_time_is_it(12)
print(time)
time = what_time_is_it(7)
print(time)
Clone this wiki locally