0
0
Pythonprogramming~10 mins

Multiple return values in Python - Interactive Code Practice

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

Complete the code to return two values from the function.

Python
def get_coordinates():
    x = 10
    y = 20
    return [1]
Drag options to blanks, or click blank then click option'
A[x, y]
B(x + y)
Cx, y
Dx
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Returning a list instead of multiple values.
Returning only one value.
2fill in blank
medium

Complete the code to unpack the returned values into variables.

Python
def get_name_and_age():
    return "Alice", 30

name, [1] = get_name_and_age()
Drag options to blanks, or click blank then click option'
Aage
Byears
Cvalue
Dinfo
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using only one variable to unpack two values.
Using a variable name that doesn't match the returned data.
3fill in blank
hard

Fix the error in the function to correctly return multiple values.

Python
def calculate():
    sum = 5 + 3
    diff = 5 - 3
    return [1]
Drag options to blanks, or click blank then click option'
A[sum, diff]
Bsum, diff
Csum + diff
D(sum)
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Returning a list instead of multiple values.
Returning the sum of the values instead of both separately.
4fill in blank
hard

Fill both blanks to create a function that returns the square and cube of a number.

Python
def powers(num):
    square = num [1] 2
    cube = num [2] 3
    return square, cube
Drag options to blanks, or click blank then click option'
A**
B*
C+
D//
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using multiplication instead of exponentiation.
Using addition or floor division operators.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps words to their length if length is greater than 3.

Python
words = ["apple", "bat", "car", "door"]
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the length as the key.
Not filtering words by length.