#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Dan Gau
#  freq.py
#

def main():

        # Get input file.
        infile = input("Please enter the input file you would like to analyze.\n")
        f = open(infile, "r")

        #creates list with zeroes
        freq = [0 for r in range(26)]
        myStr = f.read()

        #Getting the frequency - for each letter, add 1 to the appropriate index.
        for i in range(len(myStr)):
                if myStr[i].lower() >= 'a' and myStr[i].lower() <= 'z':
                        freq[ord(myStr[i].lower())-ord('a')] += 1

        #Printing the graph
        print("Here is the frequency chart:\n")

        # Start at top of chart, moving down.
        for i in range(max(freq)):
                print(max(freq) - i, "\t", sep="", end="")

                # For each char, see if the freq is high enough to print a star
                for j in range(26):
                        if freq[j] >= max(freq)-i:
                                print("*", sep="", end="")
                        else:
                                print(" ", sep="", end="")
                print()

        # Print the bottom of the chart.
        print("\t--------------------------")
        print("\t", sep="", end="")
        for i in range(26):
                print(chr(i + ord('a')), sep="", end="")

        # Close file
        f.close()

main()
