0
0
Agentic_aiml~10 mins

Input validation and sanitization in Agentic Ai - Interactive Code Practice

Choose your learning style8 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Astr
Bint
Clist
Ddict
Attempts:
3 left
2fill in blank
medium

Complete 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'
Areplace
Bsplit
Cstrip
Dlower
Attempts:
3 left
3fill in blank
hard

Fix 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'
Abool
Bint
Cfloat
Dstr
Attempts:
3 left
4fill in blank
hard

Fill 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'
Alen(word)
B>
C<
Dword
Attempts:
3 left
5fill in blank
hard

Fill 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'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left