0
0
Pythonprogramming~10 mins

reversed() function 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 reverse the list using the reversed() function.

Python
numbers = [1, 2, 3, 4, 5]
reversed_numbers = list([1](numbers))
print(reversed_numbers)
Drag options to blanks, or click blank then click option'
Areverse
Breversed
Csort
Dappend
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'reverse' which is a list method, not a function.
Using 'sort' which sorts the list, not reverses it.
2fill in blank
medium

Complete the code to print each character of the string in reverse order using reversed().

Python
word = "hello"
for char in [1](word):
    print(char, end='')
Drag options to blanks, or click blank then click option'
Asort
Breverse
Creversed
Dlist
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Trying to use 'reverse' which is not a function.
Using 'list' which converts to list but does not reverse.
3fill in blank
hard

Fix the error in the code to correctly reverse the tuple using reversed().

Python
data = (10, 20, 30)
reversed_data = [1](data)
print(tuple(reversed_data))
Drag options to blanks, or click blank then click option'
Areverse
Blist
Csort
Dreversed
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using 'reverse' which is a list method, not available for tuples.
Using 'sort' which is not valid for tuples.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 characters.

Python
words = ['apple', 'bat', 'carrot', 'dog']
lengths = [1]: len(word) for word in words if len(word) [2] 3
Drag options to blanks, or click blank then click option'
A{word
B>
C>=
D[word
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets instead of curly braces for dictionary.
Using '>=' instead of '>' which includes words of length 3.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 characters.

Python
words = ['apple', 'bat', 'carrot', 'dog']
result = [1]: [2] for word in words if len(word) [3] 3
Drag options to blanks, or click blank then click option'
A{word.upper()
Blen(word)
C>
D[word.upper()
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using square brackets instead of curly braces for dictionary.
Not converting words to uppercase for keys.
Using '>=' instead of '>' in the condition.