0
0
Intro to Computingfundamentals~10 mins

Serverless computing basics in Intro to Computing - Interactive Code Practice

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

Complete the code to define a serverless function that returns a greeting message.

Intro to Computing
def handler(event, context):
    return [1]
Drag options to blanks, or click blank then click option'
Aevent + context
Bprint("Hello from serverless!")
Creturn "Hello from serverless!"
D"Hello from serverless!"
Attempts:
3 left
💡 Hint
Common Mistakes
Including 'return' inside the blank again causes syntax errors.
Using print instead of returning the message.
2fill in blank
medium

Complete the code to extract the 'name' value from the event dictionary in a serverless function.

Intro to Computing
def handler(event, context):
    name = event[1]
    return f"Hello, {name}!"
Drag options to blanks, or click blank then click option'
A("name")
B["name"]
C.name
D{'name'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets.
Using dot notation which doesn't work for dictionaries.
3fill in blank
hard

Fix the error in the serverless function code to correctly check if the event has a 'user' key.

Intro to Computing
def handler(event, context):
    if [1] in event:
        return "User found"
    else:
        return "User not found"
Drag options to blanks, or click blank then click option'
A'user'
Buser
C"user"
Devent['user']
Attempts:
3 left
💡 Hint
Common Mistakes
Using unquoted user causes NameError.
Using event['user'] in the condition causes a KeyError if key missing.
4fill in blank
hard

Fill both blanks to create a serverless function that returns the length of a list passed in the event under 'items'.

Intro to Computing
def handler(event, context):
    items = event[1]
    count = [2](items)
    return count
Drag options to blanks, or click blank then click option'
A["items"]
Blen
C("items")
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for dictionary access.
Using variable name 'count' instead of the function 'len'.
5fill in blank
hard

Fill all three blanks to create a serverless function that filters even numbers from a list in the event under 'numbers' and returns the filtered list.

Intro to Computing
def handler(event, context):
    numbers = event[1]
    evens = [num for num in numbers if num [2] 2 == 0]
    return [3]
Drag options to blanks, or click blank then click option'
A["numbers"]
B%
Cevens
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using parentheses instead of square brackets for dictionary access.
Using wrong operator instead of modulo '%'.
Returning the original list instead of the filtered list.