You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: Print out what time it is based on the current hour
1) Set up the function:
a) Create a new function with a parameter representing the hour
b) Check for each time, and if it matches, 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
defwhat_time_is_it(hour):
ifhour==2:
return"taco time 🌮"elifhour==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)