Complete the code to return the sum of two numbers.
def add(a, b): return a [1] b
The return statement sends back the result of a + b.
Complete the code to return the first character of a string.
def first_char(s): return s[1]
Index 0 gives the first character of a string in Python.
Fix the error in the function to return the square of a number.
def square(n): result = n [1] n return result
Multiplying n by itself gives the square.
Fill both blanks to return a dictionary with words as keys and their lengths as values for words longer than 3 letters.
def word_lengths(words): return {word: [1] for word in words if len(word) [2] 3}
The dictionary comprehension uses len(word) as value and filters words with length greater than 3 using >.
Fill all three blanks to return a dictionary with uppercase keys and values only if the value is positive.
def filter_positive(data): return { [1]: [2] for k, v in data.items() if v [3] 0 }
The dictionary comprehension uses uppercase keys with k.upper(), values v, and filters values greater than zero with >.