Hey I am really stuck on how to do this because I don't rember any section on how to reverse!!! please help me!!!! Thank you
Please provide a link to the exercise.
Practice makes Perfect
def reverse(text): #1 rev = '' #2 count = len(text) #3 while count > 0: #4 rev += text[count - 1] #5 count -= 1 #6 return rev #7
Line 1: I defined a function reverse with the argument (text).
Line 2: rev is an empty string.
Line 3: Count is equal to length of the functions argument (text).
Line 4: While count, or the length of text, is greater than 0:
Line 5: rev (the empty string) is equal to itself plus the function argument (text)-its length minus one.
Line 6: Count is equal to itself minus one.
Line 7: It will return 'rev', the empty string that now has something in it.
Note that return does not print anything, to print you need to write 'print'. Your output should be none.
Please provide a link next time
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.