Reverse characters

Program for reversing first three characters and next three characters in a word with even length.

word = input('Enter word: ')

if len(word)%2==0 and len(word) >= 6 :
      r1 = word[0:3] 
      r2 = word[3:6] 
      s1 = r1[::-1] 
      s2 = r2[::-1] 
      print('Word after reversing first 3 letters and next 3  letters:',s1+s2)

Output
Enter word: PYTHON
Word after reversing first 3 letters and next 3 letters: TYPNOH

Published by Python programming examples for beginners

Abhay Gadkari is an IT professional having around experience of 20+ years in IT industry. He worked on web technologies and databases with Insurance and ERP projects.