In [ ]:
def main():
    filename = input("Enter a filename: ").strip()
    infile = open(filename, "r") # Open the file

    counts = 26 * [0] # Create and initialize counts
    print(counts)
    for line in infile:
        # Invoke the countLetters function to count each letter
        countLetters(line.lower(), counts)
    
    # Display results
    for i in range(len(counts)):
        if counts[i] != 0:
            print(chr(ord('a') + i) + " appears " + str(counts[i])
              + (" time" if counts[i] == 1 else " times"))
    print(counts)
    
    toplam_harf=0
    for i in range(len(counts)):
        toplam_harf+=counts[i]
    print(toplam_harf)
    
    
    infile.close() # Close file
        
        
    
  
# Count each letter in the string 
def countLetters(line, counts): 
    for ch in line:
        if ch.isalpha():
            counts[ord(ch) - ord('a')] += 1

main() # Call the main function

In [ ]:
print("d")

In [ ]: