nanokatka

strings-task1

Feb 7th, 2020
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. text=input("Input text:")
  2.  
  3. #loops
  4. text2=[]
  5. textrev2=''
  6. for i in range(len(text)):
  7. text2.append(text[-(i+1)])
  8. textrev2=textrev2+text2[i]
  9. print("Using loops", textrev2)
  10.  
  11. # slices
  12. print("Using slices:", text[::-1])
  13.  
  14. #reversed (hasd to do a bit Googling here, because the "list" in fron of reversed was not obvious)
  15. textrev3=''
  16. text3=list(reversed(text))
  17. for i in text3:
  18. textrev3=textrev3+str(i)
  19. print("with reveresed:", textrev3)
Add Comment
Please, Sign In to add comment