0
0
DSA Pythonprogramming~10 mins

String Basics and Memory Representation in DSA Python - Interactive Practice

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

Complete the code to get the length of the string.

DSA Python
word = "hello"
length = len([1])
print(length)
Drag options to blanks, or click blank then click option'
A"word"
Bword
Clen
Dhello
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the variable name like "word" which makes it a string literal.
Using the function name len inside len().
2fill in blank
medium

Complete the code to get the first character of the string.

DSA Python
word = "world"
first_char = word[[1]]
print(first_char)
Drag options to blanks, or click blank then click option'
A-1
B1
Cword
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 1 as the index which gives the second character.
Using -1 which gives the last character.
3fill in blank
hard

Fix the error in the code to get the last character of the string.

DSA Python
word = "python"
last_char = word[[1]]
print(last_char)
Drag options to blanks, or click blank then click option'
A-len(word)
B0
Clen(word) - 1
Dlen(word)
Attempts:
3 left
💡 Hint
Common Mistakes
Using len(word) which is out of range.
Using 0 which gives the first character.
4fill in blank
hard

Fill both blanks to create a substring from the second to the fourth character (inclusive).

DSA Python
word = "example"
substring = word[[1]:[2]]
print(substring)
Drag options to blanks, or click blank then click option'
A1
B4
C5
D3
Attempts:
3 left
💡 Hint
Common Mistakes
Using end index 3 which excludes the fourth character.
Using start index 2 which skips the second character.
5fill in blank
hard

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

DSA Python
words = ["cat", "house", "dog", "elephant"]
lengths = [1]: [2] for word in words if len(word) [3] 3
print(lengths)
Drag options to blanks, or click blank then click option'
A{word}
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Missing the opening curly brace.
Using the wrong comparison operator.
Swapping key and value positions.