Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to reverse the string using slicing.
DSA Python
reversed_str = original_str[1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using [:] returns the original string without reversing.
Using [1:] skips the first character but does not reverse.
Using [::-2] reverses but skips characters.
✗ Incorrect
Using slicing with [::-1] reverses the string by stepping backwards one character at a time.
2fill in blank
mediumComplete the code to reverse the string using the reversed() function and join.
DSA Python
reversed_str = ''.[1](reversed(original_str))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using append() is for lists, not strings.
Using split() breaks strings into lists, not reverse.
Using replace() changes characters, not order.
✗ Incorrect
The join() method combines characters from reversed() into a new reversed string.
3fill in blank
hardFix the error in the code to reverse the string using a for loop.
DSA Python
reversed_str = '' for char in original_str: reversed_str = char [1] reversed_str
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * or - operators causes errors or wrong results.
Appending char after reversed_str does not reverse.
✗ Incorrect
Concatenating the current character before the reversed string builds the reversed string step by step.
4fill in blank
hardFill both blanks to reverse the string using a list and the reverse() method.
DSA Python
char_list = list(original_str) char_list.[1]() reversed_str = ''.[2](char_list)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sort() changes order but sorts alphabetically, not reverses.
Using append() is for adding elements, not reversing.
Using join() before reverse() will not reverse the string.
✗ Incorrect
reverse() reverses the list in place, and join() combines the list into a string.
5fill in blank
hardFill all three blanks to reverse the string using recursion.
DSA Python
def reverse_str(s): if len(s) [1] 0: return '' else: return reverse_str(s[[3]]) + s[[2]]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using != in base case causes infinite recursion.
Using -1 as index returns last char, but recursion needs first char then rest.
Incorrect slicing causes errors or wrong output.
✗ Incorrect
Base case checks if string is empty (length 0). Then return recursive call on rest plus first char.