30 Days of Code in HackerRank with Python (Day 6: Let’s Review)

Saptashwa Banerjee
1 min readJul 8, 2020

--

Objective
Today we’re expanding our knowledge of Strings and combining it with what we’ve already learned about loops. Check out the Tutorial tab for learning materials and an instructional video!

Task
Given a string, S, of length N that is indexed from 0 to N-1, print its even-indexed and odd-indexed characters as 2 space-separated strings on a single line (see the Sample below for more detail).

Note: 0 is considered to be an even index.

Sample Input

2
Hacker
Rank

Sample Output

Hce akr
Rn ak
Code for Day 6

Explanation
Here we have to break the given input into two parts one will contain all the even terms and another all the odd terms. Basically in the for loop we take the number of input string and then for S[0::2] it prints even terms and for S[1::2] prints the odd terms, and “ “ is for the space between them.

So i hope you got this code, So see you in Day 7.

--

--