1st Way :
1
2
3
4
5
6
7
8
9
10
11 | string_data=input("Enter a string: ") print("Characters present at even index position: ") i=0 while i<len(string_data): print(string_data[i]) i=i+2 print("Characters present at odd index position: ") i=1 while i<len(string_data): print(string_data[i]) i=i+2 |
2nd Way:
string_data=input("Enter a string: ")
print("Characters present at even index position: ")
print(string_data[::2]) # or
print(string_data[0::2])
print("Characters present at odd index position: ")
print(string_data[1::2])
No comments:
Post a Comment