Advertisement
ralphdc09

its102.pr.wk.05.07.num03

Oct 22nd, 2021
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. # define a function that reverse a string
  2. # reverse_string()
  3. def reverse_string(str1):
  4.     rstr1 = ''
  5.     index = len(str1)
  6.     while index > 0:
  7.         rstr1 += str1[index - 1]
  8.         index = index - 1
  9.     return rstr1
  10.  
  11.  
  12. # initialize a string to be reverse
  13. string = 'ralph'
  14. # print the string
  15. print("The string is: ", string)
  16.  
  17. # call function reverse_string() to reverse the string
  18. print("The reverse of the string is: ", reverse_string(string))  # this will print the reverse of string 'ralph'
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement