0
0
Intro to Computingfundamentals~10 mins

Functions (reusable code blocks) 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 function named greet.

Intro to Computing
def [1]():
    print("Hello!")
Drag options to blanks, or click blank then click option'
Asay_hello
Bgreet
Chello
Dprint
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different function name than 'greet'.
Forgetting to add parentheses after the function name.
2fill in blank
medium

Complete the code to call the function greet.

Intro to Computing
[1]()
Drag options to blanks, or click blank then click option'
Aprint
Bsay_hello
Chello
Dgreet
Attempts:
3 left
💡 Hint
Common Mistakes
Using print() instead of the function name.
Forgetting the parentheses after the function name.
3fill in blank
hard

Fix the error in the function definition to accept a name parameter.

Intro to Computing
def greet([1]):
    print(f"Hello, {name}!")
Drag options to blanks, or click blank then click option'
Anames
BName
Cname
Dnam
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different parameter name than 'name'.
Capitalizing the parameter name incorrectly.
4fill in blank
hard

Fill both blanks to define and call a function that adds two numbers.

Intro to Computing
def add([1], [2]):
    return a + b

result = add(3, 4)
Drag options to blanks, or click blank then click option'
Aa
Bb
Cx
Dy
Attempts:
3 left
💡 Hint
Common Mistakes
Using parameter names that don't match the return statement.
Using more or fewer parameters than needed.
5fill in blank
hard

Fill all three blanks to create a function that returns the square of a number and call it.

Intro to Computing
def square([1]):
    return [2] * [3]

result = square(5)
Drag options to blanks, or click blank then click option'
Anum
Dnumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names in the parameter and return statement.
Using a variable name not defined as a parameter.