Write a program to find the first and the last occurence of the letter 'o' and character ',' in "hello, world".
Answers
Answered by
11
Answer:
Input : str = "geeks", x = 'e'
Output : 2
Last index of 'e' in "geeks" is: 2
Input : str = "Hello world!", x = 'o'
O is
: 7
Last index of 'o' is: 7
Answered by
4
Answer:
n="Hello,World"
a=-1
x=-1
b=0
y=0
for i in n:
a=a+1
if i=='o' :
break
print(a,"is the index of o from forward")
for i in n:
x=x+1
if i==',':
break
print(x,"is the index of , from forward")
for i in reversed(n):
b=b+1
if i=='o':
break
print(b,"is the index of o from backwards")
for i in reversed(n):
y=y+1
if i==',':
break
print(y,"is the index of , from backwards")
Explanation:
firstly it check from forward and then from backwards
this is for python
Similar questions
Chemistry,
5 months ago
Science,
5 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Physics,
1 year ago