0
0
Pythonprogramming~10 mins

Built-in scope 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 print the absolute value of -5 using a built-in function.

Python
print([1](-5))
Drag options to blanks, or click blank then click option'
Aabs
Bmin
Cmax
Dlen
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using len() which is for length of collections.
Using max() or min() which compare values but don't change sign.
2fill in blank
medium

Complete the code to convert the string '123' to an integer using a built-in function.

Python
number = [1]('123')
print(number + 1)
Drag options to blanks, or click blank then click option'
Afloat
Bstr
Cint
Dbool
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using str() which keeps it as text.
Using float() which converts to decimal number.
Using bool() which converts to True or False.
3fill in blank
hard

Fix the error in the code by completing the blank with the correct built-in function to get the length of the list.

Python
my_list = [1, 2, 3, 4]
print([1](my_list))
Drag options to blanks, or click blank then click option'
Alen
Blength
Csize
Dcount
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using count which is a list method but needs an argument.
Using length or size which are not built-in functions in Python.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, using built-in functions.

Python
words = ['apple', 'bee', 'cat']
lengths = { [1]: [2] for word in words }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.upper()
Dword.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using word.upper() or word.lower() as values instead of lengths.
Using len without parentheses.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values that are True if the length is greater than 3.

Python
words = ['dog', 'elephant', 'cat']
result = { [1]: [2] > 3 for [3] in words }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Cword
Dword.lower()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using word.lower() instead of uppercase for keys.
Using word instead of len(word) for values.
Not using the loop variable word correctly.