Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # define a function that reverse a string
- # reverse_string()
- def reverse_string(str1):
- rstr1 = ''
- index = len(str1)
- while index > 0:
- rstr1 += str1[index - 1]
- index = index - 1
- return rstr1
- # initialize a string to be reverse
- string = 'ralph'
- # print the string
- print("The string is: ", string)
- # call function reverse_string() to reverse the string
- print("The reverse of the string is: ", reverse_string(string)) # this will print the reverse of string 'ralph'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement