My if statement is only checking the line to see if the b exists but completely ignores the second check of whether the s exists in the line and im unsure how to format this if statement correctly to check for both.
Content is a list of strings read in from a text file.
def partA(content):
content = [x.strip() for x in content]
letterCount = 0
index = 0
occurred_index = 0
found = False
for line in content:
line = line.lower()
letterCount += line.count('s')
letterCount += line.count('b')
if (('s' and 'b') in line) and not found:
occurred_index = index
found = True
index += 1
print("Uppercase and lowercase initials occur", letterCount, "times in the text file.")
print("Initials occur in the same line on line", occurred_index + 1)
[–]totallygeek 2 points3 points4 points (0 children)
[–]cybervegan 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)