0
0
DSA Pythonprogramming~10 mins

String Reversal Approaches 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 reverse the string using slicing.

DSA Python
reversed_str = original_str[1]
Drag options to blanks, or click blank then click option'
A[1:]
B[:]
C[::-1]
D[::-2]
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.
2fill in blank
medium

Complete 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'
Asplit
Bjoin
Cappend
Dreplace
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.
3fill in blank
hard

Fix 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'
A/
B*
C-
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using * or - operators causes errors or wrong results.
Appending char after reversed_str does not reverse.
4fill in blank
hard

Fill 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'
Areverse
Bjoin
Cappend
Dsort
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.
5fill in blank
hard

Fill 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'
A==
B0
C1:
D!=
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.