fork download
  1. def rearrange_word(word):
  2. length = len(word)
  3. if length % 3 != 0:
  4. return "TANTRUM"
  5.  
  6. section_length = length // 3
  7. first_section = word[:section_length][::-1]
  8. middle_section = word[section_length:2*section_length]
  9. third_section = word[2*section_length:][::-1]
  10.  
  11. return first_section + middle_section + third_section
  12.  
  13. # Example usage
  14. print(rearrange_word("racecar")) # Output: carerat
  15. print(rearrange_word("bounce")) # Output: TANTRUM
  16. # your code goes here
Success #stdin #stdout 0.03s 9668KB
stdin
Standard input is empty
stdout
TANTRUM
obunec