Saturday, 22 January 2022

Pythonslip15b-Write a python program to accept string and remove the characters which have odd index values of given string using user defined function.

Write a python program to accept string and remove the characters which have odd index values of given string using user defined function.  

def MyString():

    Str=input("Enter any String: ")

    cnt=len(Str)

    newString=""

    for i in range(0,cnt):

        if i%2 ==0:

            newString=newString + Str[i]

    print("New String with removed odd Index Character: ",newString)

MyString()