SimeonTs

SUPyF2 Lists-Advanced-Exercise - 07. Decipher this!

Oct 10th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. """
  2. Lists Advanced - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1731#5
  4.  
  5. SUPyF2 Lists-Advanced-Exercise - 07. Decipher this!
  6.  
  7. Problem:
  8. You are given a secret message you need to decipher. Here are the things you need to know to decipher it:
  9. For each word:
  10. • the second and the last letter are switched (e.g. Hello becomes Holle)
  11. • the first letter is replaced by its character code (e.g. H becomes 72)
  12. Example:
  13. Input:                  Output:
  14. 72olle 103doo 100ya     Hello good day
  15. 82yade 115te 103o       Ready set go
  16. """
  17. coded_list = input().split()
  18.  
  19. for code in coded_list:
  20.     new_word = chr(int("".join([num for num in code if num.isdigit()])))
  21.     the_rest = [letter for letter in code if letter.isalpha()]
  22.     if len(the_rest) > 1:
  23.         the_rest[0], the_rest[-1] = the_rest[-1], the_rest[0]
  24.         new_word += "".join(the_rest)
  25.     else:
  26.         new_word += the_rest[0]
  27.     print(new_word, end=" ")
Add Comment
Please, Sign In to add comment