Write a program that reads a sentence from the keyboard. The sentence has been encrypted so that the message consists of only the first five characters with even-numbered indexes. All other characters should be discarded. Decrypt the sentence and output the result. For example, if the user inputs “Hiejlzl3ow”, your output should be Hello.
Write a
Python program:
# function for sentence
def sentence(str):
# for storing the decrypt result
result = ""
for i in range(len(str)):
# encrypted sentence consists first five characters with even number indexes
if i % 2 == 0:
result = result + str[i]
return result
# Enter the string
str = input('Enter the string: ')
# display the decrypted result of given string
print(sentence(str))
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images