TIP102 Unit 1 Session 1 Standard (Click for link to problem statements)
Understand what the interviewer is asking for by using test cases and questions about the problem.
year
is not 2005, 2008, or 2012?
"Christopher Nolan did not release a Batman movie in <year>."
, with <year>
replaced by the given year.Q: What if the year
is one of the specified years?
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}.".
⚠️ Common Mistakes
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}.")