-
Notifications
You must be signed in to change notification settings - Fork 254
Trilogy
Raymond Chen edited this page Aug 1, 2024
·
2 revisions
TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)
- 💡 Difficulty: Easy
- ⏰ Time to complete: 5 mins
- 🛠️ Topics: Functions, Conditionals
Understand what the interviewer is asking for by using test cases and questions about the problem.
- Established a set (2-3) of test cases to verify their own solution later.
- Established a set (1-2) of edge cases to verify their solution handles complexities.
- Have fully understood the problem and have no clarifying questions.
- Have you verified any Time/Space Constraints for this problem?
- The function
trilogy()
should accept an integer year and print the title of the Batman movie released that year based on a specified table.
HAPPY CASE
Input: 2008
Output: The Dark Knight
Input: 2012
Output: The Dark Knight Rises
EDGE CASE
Input: 1998
Output: Christopher Nolan did not release a Batman movie in 1998.
Plan the solution with appropriate visualizations and pseudocode.
General Idea: Define the function with conditional statements to check the input year.
1. Define the function `trilogy(year)`.
2. Use if-elif-else statements to check the year:
a. If year is 2005, print "Batman Begins".
b. If year is 2008, print "The Dark Knight".
c. If year is 2012, print "The Dark Knight Rises".
d. If none of the above, print "Christopher Nolan did not release a Batman movie in {year}.".
- Not covering all conditions.
- Forgetting to format the output string correctly.
Implement the code to solve the algorithm.
def trilogy(year):
if year == 2005:
print("Batman Begins")
elif year == 2008:
print("The Dark Knight")
elif year == 2012:
print("The Dark Knight Rises")
else:
print(f"Christopher Nolan did not release a Batman movie in {year}.")