Write a Python program which asks a user for a word and performs letters manipulation. If the word is empty, the program should print the message empty! Otherwise, if the word has between one and four letters (inclusive), the program should print the reversed word. Otherwise, the program should print a word made of the first two and the last two letters of the original word. Your program should match the sample output as displayed below.

Sample Output
Enter a word:
Result: empty!

Enter a word: bio
Result: oib

Enter a word: memory
Result: mery

Respuesta :

Answer:

The program is as follows:

word = input("Enter a word: ")

if word:

   if len(word) <= 4:

       word = word[::-1]

   else:

       word = word[0]+word[1]+word[-2]+word[-1]

   print(word)

else:

   print('empty!')

Explanation:

This gets input for word from the user

word = input("Enter a word: ")

If input is not empty

if word:

This checks if the length is less than or equal to 4 characters

   if len(word) <= 4:

If yes, this reverses the word

       word = word[::-1]

If otherwise,

   else:

This gets the first, second, second to last two characters

       word = word[0]+word[1]+word[-2]+word[-1]

Print the new string

   print(word)

Print empty, if input is empty

else:

   print('empty!')