0
0
Pythonprogramming~10 mins

max() and min() 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 find the maximum number in the list.

Python
numbers = [3, 7, 1, 9, 4]
max_value = [1](numbers)
print(max_value)
Drag options to blanks, or click blank then click option'
Amax
Bmin
Csum
Dlen
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using min() instead of max()
Using sum() which adds numbers instead of finding max
2fill in blank
medium

Complete the code to find the minimum number in the list.

Python
values = [10, 5, 8, 2, 7]
min_value = [1](values)
print(min_value)
Drag options to blanks, or click blank then click option'
Amax
Bmin
Csorted
Dlen
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using max() instead of min()
Using sorted() which returns a list, not a single value
3fill in blank
hard

Fix the error in the code to correctly find the maximum value.

Python
data = [4, 9, 2, 6]
max_value = max[1]data
print(max_value)
Drag options to blanks, or click blank then click option'
A( )
B{ }
C[
D< >
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets which are for lists
Using curly braces which are for sets or dictionaries
4fill in blank
hard

Fill both blanks to create a dictionary with word lengths only for words longer than 3 letters.

Python
words = ['cat', 'elephant', 'dog', 'lion']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using < instead of > in the condition
Using the word itself instead of its length
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only for values greater than 0.

Python
data = {'a': 1, 'b': 0, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using original keys without uppercase
Using < instead of > in the condition
Using keys as values instead of v