Write a Python function to reverses a string if its length is a multiple of 4


This program is written in the Python programming language and it reverses the input string if its length is a multiple of 4, otherwise it returns the original string. It does this in two steps:

  • The first step is to get the input string from the user using the "input" function. The input string is stored in the variable "str".
  • The program then checks the length of the string "str" using the built-in "len" function. If the length is a multiple of 4, the program reverses the string using the "reversed" function and the "join" method. The reversed string is then printed to the console using the "print" function. If the length is not a multiple of 4, the program simply prints the original string "str" to the console without reversing it.

Source Code

str=input("Enter the String :")
if len(str) % 4 == 0:
   print(''.join(reversed(str)))
else:
	print(str)

Output

Enter the String :Computer
retupmoC

Example Programs