month_list = ["January", "February", "March", "April", "May"] expense_list = [2340, 2500, 2100, 3100, 2980] e = int(input("Enter expense amount: ")) month = -1 for i in range(len(expense_list)): if e == expense_list[i]: month = i break if month != -1: print('You spent', e, 'in', month_list[month]) else: print('You didn\'t spend', e, 'in any month') Use code with caution. 📑 Core Reference Sheet: Direct Concept Comparisons Concept / Token Purpose / Rule Key Common Mistake Evaluates a primary conditional expression. Missing the trailing : colon character. elif Tests an alternate condition if preceding checks fail. Using else if instead of the explicit elif token. else Executes a fallback block if all conditions are False . Trying to pass a direct evaluation condition to it. == Compares if two values are completely equal. Using a single = (which assigns a variable instead). int(input()) Captures a user response and transforms it into an integer.
: New users can explore up to five lessons per course through a free 7-day trial to see the latest curriculum updates. LinkedIn New Zealand 1. Introduction to Python With ANSWERS — UCL Geography code avengers answers python 2 new
Tasks frequently ask you to find how many times a specific value appears. elif Tests an alternate condition if preceding checks fail