Advertisement
X-88

Compare Revese String

May 19th, 2021
736
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. inp = input('>>> ')
  2. spr = '=======================\n'
  3. def revstr(n):
  4.     n = "".join(reversed(n))
  5.     return n
  6.    
  7. def revstr2(n):
  8.     s = ''
  9.     for i in n:
  10.         s = i + s
  11.     return s
  12.        
  13. def revstr3(n):
  14.     return n[::-1]
  15.    
  16. def revstr4(n):
  17.     s = ''
  18.     for i in range(len(n), 0, -1):
  19.         s += n[i - 1]
  20.     return s
  21.    
  22. def revstr5(n):
  23.     s = ''
  24.     i = len(n)
  25.     while(i > 0):
  26.         s += n[i - 1]
  27.         i -= 1
  28.     return s
  29.  
  30. #--------------------------------->    
  31. print(revstr(inp))
  32. print(revstr2(inp))
  33. print(revstr3(inp))
  34. print(revstr4(inp))
  35. print(revstr5(inp))
  36. print('ori:', inp, 'rev:', inp[::-1])
  37. #--------------------------------->
  38. data = inp[::-1]
  39. print(data)
  40. if (
  41. (data == revstr(inp)) or
  42. (data == revstr2(inp)) or
  43. (data == revstr3(inp)) or
  44. (data == revstr4(inp)) or
  45. (data == revstr5(inp)) or
  46. (data == inp[::-1])
  47. ):
  48.     print(spr + data, ',string sesuai dari kebalikan', inp)
  49. else:
  50.     print(spr + 'uhh..., payah')
Advertisement
RAW Paste Data Copied
Advertisement