0

Becouse show No output???

x = 'qwerty' res=0 if 'q' in x: res+=1 elif 'q' in x: res+=1 print(res)

2nd May 2021, 3:31 AM
Darién Domínguez Hernández
Darién Domínguez Hernández - avatar
3 Antworten
+ 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
2nd May 2021, 4:00 AM
TOLUENE
TOLUENE - avatar
+ 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))
2nd May 2021, 8:42 AM
Shadoff
Shadoff - avatar
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
2nd May 2021, 8:41 AM
A͢J
A͢J - avatar