Advertisement
SimeonTs

SUPyF2 Text-Processing-Lab - 01. Reverse Strings

Oct 26th, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.33 KB | None | 0 0
  1. """
  2. Text Processing - Lab
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1739#0
  4.  
  5. SUPyF2 Text-Processing-Lab - 01. Reverse Strings
  6.  
  7. Problem:
  8. You will be given series of strings until you receive an "end" command.
  9. Write a program that reverses strings and prints each pair on separate line in format "{word} = {reversed word}".
  10.  
  11. Examples:
  12. |------------|---------------------|
  13. |  Input:    |   Output:           |
  14. |------------|---------------------|
  15. |  helLo     |   helLo = oLleh     |
  16. |  Softuni   |   Softuni = inutfoS |
  17. |  bottle    |   bottle = elttob   |
  18. |  end       |                     |
  19. |------------|---------------------|
  20. |  Dog       |   Dog = goD         |
  21. |  caT       |   caT = Tac         |
  22. |  chAir     |   chAir = riAhc     |
  23. |  enD       |                     |
  24. |------------|---------------------|
  25. """
  26. # Solution #1:
  27. """
  28. while True:
  29.    word = input()
  30.    if word == "end":
  31.        break
  32.    print(f"{word} = {word[::-1]}")
  33. """
  34. # Solution #2:
  35. """
  36. while True:
  37.    word = input()
  38.    if word == "end":
  39.        break
  40.    reverse_word = ""
  41.    for letter in reversed(word):
  42.        reverse_word += letter
  43.    print(f"{word} = {reverse_word}")
  44. """
  45. # Solution #3
  46. while True:
  47.     word = input()
  48.     if word == "end":
  49.         break
  50.     print(f"{word} = {''.join(reversed(word))}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement