a=input("enter string: ")
count=0
if 'emma' in a:
count=count+1
else:
print("not found")
print("no of emmas in string:"+count)
Asked
Active
Viewed 44 times
-4
-
2Why should it count more than 1? You don't have a loop, so it only executes once. – Barmar Aug 11 '20 at 07:19
-
1what is the problem ? if you run it only once then you can't get bigger value. You didn't show what data you use and what result you expected. – furas Aug 11 '20 at 07:19
2 Answers
0
Use .count
on the string instead
a=input("enter string: ")
print("no of emmas in string: {} ".format(a.count('emma')))
Output:
enter string: emma emma
no of emmas in string: 2

bigbounty
- 16,526
- 5
- 37
- 65