Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to check if the input is a non-empty string.
Agentic_ai
def is_valid_input(user_input): return isinstance(user_input, [1]) and len(user_input) > 0
Drag options to blanks, or click blank then click option'
Attempts:
3 left
2fill in blank
mediumComplete the code to remove leading and trailing spaces from the input string.
Agentic_ai
def sanitize_input(user_input): return user_input.[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
3fill in blank
hardFix the error in the code to safely convert input to an integer.
Agentic_ai
def convert_to_int(user_input): try: return [1](user_input) except ValueError: return None
Drag options to blanks, or click blank then click option'
Attempts:
3 left
4fill in blank
hardFill both blanks to create a dictionary of word lengths for words longer than 3 characters.
Agentic_ai
words = ['apple', 'cat', 'banana', 'dog'] lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
5fill in blank
hardFill all three blanks to filter and transform a dictionary with values greater than 0.
Agentic_ai
data = {'a': 1, 'b': -2, 'c': 3}
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }} Drag options to blanks, or click blank then click option'
Attempts:
3 left
