Complete the code to return the sum of two numbers.
def add_numbers(a, b): return a [1] b
The return statement sends back the sum of a and b using the + operator.
Complete the code to return the length of the given string.
def string_length(s): return [1](s)
size() or length().The built-in function len() returns the number of characters in a string.
Fix the error in the method to return the square of a number.
def square(num): result = num [1] num return result
To get the square, multiply the number by itself using the * operator.
Fill both blanks to create a method that returns a dictionary with words as keys and their lengths as values, but only 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) to get the length and filters words with length greater than 3 using >.
Fill all three blanks to create a method that returns a dictionary with uppercase keys and values only for items with positive values.
def filter_and_uppercase(data): return { [1]: [2] for k, v in data.items() if v [3] 0 }
The keys are converted to uppercase with k.upper(), values are kept as v, and only items with values greater than 0 are included using >.