Becouse show No output??? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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