46 Python Problems

From http://www.ling.gu.se/~lager/python_exercises.html

Files Code and Result

poblem19.py

problem1.py

problem2.py

problem3.py

problem4.py

problem5.py

problem6.py

problem7.py

problem8.py

problem9.py

problem10.py

problem11.py

problem12.py

problem13.py

problem14.py

problem15.py

problem16.py

problem17.py

problem18.py

problem20.py

problem21.py

problem22.py

problem23.py

problem24.py

problem25.py

problem26.py

problem27.py

problem28.py

problem29.py

problem30.py

problem31.py

problem32.py

problem33.py

problem34.py

problem36.py

problem37.py

problem38.py

problem42.py

problem43.py

problem44.py

problem45.py

problem46.py

problem34.py

# requires a text file

def char_freq_table():
            '''(text file) -> histogram
            generate a histogram based on a text file
            '''
            store = ''
            dict = {}
            input_text = input('Enter a text file: ')
            file = open(input_text, 'r')
            for line in file:
                    line = line.strip()
                    for letter in line:
                            if letter.isalpha():
                                    store += letter

            for letter in store:
                    counter = store.count(letter)
                    dict[letter] = counter
                    store.replace(letter, '')

            for entry in dict:
                    yield(entry, 'x' * dict[entry])

for x in char_freq_table():
        print(x)

Result

Traceback (most recent call last):
  File "/tmp/tmprbfi73l6", line 25, in <module>
    for x in char_freq_table():
  File "/tmp/tmprbfi73l6", line 9, in char_freq_table
    input_text = input('Enter a text file: ')
EOFError: EOF when reading a line