Reputation: 7
Write a Python program to count the number of strings where the string length is 2 or more and the first and last character are same from a given list of strings
n=int(input())
count=0
for j in range(0,n):
string=input()
for i in string:
if len(i)>=2:
if i[0]==i[-1]:
count=count+1
print(count)
why output is always showing zero?
Upvotes: 1
Views: 484
Reputation: 1967
You instead need to append the individual inputs to a strings
array when building them, then loop over them and check your conditions:
n=int(input())
strings = []
count=0
for j in range(0,n):
strings.append(input())
for i in strings:
if len(i)>=2:
if i[0]==i[-1]:
count=count+1
print(count)
Upvotes: 1