-2

In a certain encrypted message which has information about the locations, the characters are jumbled such that first character of the first word is followed by the first character of the second word, then it is followed by second character of the first word and so on.

Let’s say the location is Chennai, Kolkata.

The encrypted message says ckhoelnknaatia.

Sample Input: ckhoelnknaatia

Sample Output: chennai, kolkata

If the size or length of the two words wouldn’t match then the smaller word is appended with # and then encrypted in the above format.

To do this, I have to follow the code snippet:

import ast, sys

input_str = sys.stdin.read()

# Type your code here

print(message1, message2)

I do not have required knowledge for ast and sys module to solve this.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Sam2021
  • 3
  • 4
  • 1
    What does this have to do with the `ast` module? You also don't need the `sys` module for the code you are supposed to write, it was only used to read the input from the user. – mkrieger1 Jul 29 '22 at 10:04
  • Please do not copy/paste assignments here. Try to solve the problem, and feel free to ask a question about a _specific_ issue you have in doing so, along with your attempts at circumventing it. – Thrastylon Jul 29 '22 at 10:12

1 Answers1

1

Try this one

import sys

input_str = input('type here\n')
# if you need system arguments while running prgram like
# python hello.py ckhoelnknaatia
# input_str = sys.argv[1]

length_of_string = len(input_str)
# 1st message stars from index 0 
message1 = input_str[0: length_of_string: 2]
# 2nd message stars from index 1 

message2 = input_str[1: length_of_string: 2]
# Remove all #s from output 
message1 = message1.replace('#', '')
message2 = message2.replace('#', '')

print(message1, message2)
Mudasir Habib
  • 704
  • 7
  • 14
  • thanks for your help but one point to ask you that if I have to use sys.stdin.read() to take the input 'ckhoelnknaatia', then how to do this ? – Sam2021 Jul 29 '22 at 13:10
  • why you need sys.stdin.read()? If its compulsory then try 'input_str = sys.stdin.read()' like in your question, but don't forget to finish input by pressing 'ctrl + d'. – Mudasir Habib Jul 30 '22 at 10:37