0
Becouse show No output???
x = 'qwerty' res=0 if 'q' in x: res+=1 elif 'q' in x: res+=1 print(res)
3 Réponses
+ 2
Remember in a
if...elif...elif...else block as soon as a block satisfies condition then other blocks aren't executed even though they are True.
Here in first if it's true and this blocks add 1 to res. So after this if elif block aren't executed
+ 1
if you want to know how many times the same letter appears in the string:
x= "aabcd"
print(x.count("a"))
the same result but different solution:
res=0
for i in x:
if i=="a":
res+=1
if you want to know the length of the string:
print(len(x))
0
Darién Domínguez Hernandez
You are getting No Output because you have written print statement inside elif but elif is not executing because if condition is satisfying.
elif only execute when condition of if statement returns false