Wednesday, November 6, 2019

printing the character at even and odd positions

# -*- coding: utf-8 -*-
"""
Created on Thu Nov  7 07:46:59 2019

@author: Onyx1
"""

a=input("Enter some string::")
i=0
print("The Characters at even positions:")
while i<len(a):
    print(a[i],end=',')
    i=i+2
i=1
print("The Characters at odd positions:")
while i<len(a):
    print(a[i],end=',')
    i=i+2

output:
Enter some string::anildurgam
The Characters at even positions:
a,i,d,r,a,The Characters at odd positions:
n,l,u,g,m,




example2:
a=input("Enter some string::")
i=0
print("The Characters at even positions:")
while i<len(a):
    print(a[i],end=',')
    i=i+2
i=1
print()
print("The Characters at odd positions:")
while i<len(a):
    print(a[i],end=',')
    i=i+2

output:
Enter some string::anildurgam
The Characters at even positions:
a,i,d,r,a,
The Characters at odd positions:
n,l,u,g,m,

No comments:

Post a Comment

python class topic video