-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforipvowels.py
More file actions
35 lines (33 loc) · 1.1 KB
/
foripvowels.py
File metadata and controls
35 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# print index positions of all vowels along with vowel present in given string
s=input('enter a string:') # s='hi@bye'
vowels='aieouAIEOU'
for ip in range(len(s)):
if s[ip] in vowels:
print(ip,s[ip])
'''
step-1 = define the given string s='hi@bye' and vowels string vowels='aieouAIEOU'
step-2 = start a for loop with loop variable ip iterating over range(len(s)) (i.e., all index positions in the string)
step-3 = in each iteration, check if character at s[ip] is present in vowels string
iteration-1:
extracted character is 'h' at index 0
it is not a vowel, so skip print and do not output
iteration-2:
extracted character is 'i' at index 1
it is a vowel, so print index and vowel: "1 i"
iteration-3:
extracted character is '@' at index 2
it is not a vowel, so skip print
iteration-4:
extracted character is 'b' at index 3
it is not a vowel, so skip print
iteration-5:
extracted character is 'y' at index 4
it is not a vowel, so skip print
iteration-6:
extracted character is 'e' at index 5
it is a vowel, so print index and vowel: "5 e"
no more characters to extract, loop ends
final output will be:
1 i
5 e
'''