Why learn programming ?

  • Computers are our "personal assistants" that can take care of many tasks on our behalf

  • Non-programmers can only a computer with the supplied applications ("apps")

  • Computer programmers can create new applications for themselves and others !
  • Benefits of learning computer programming:

      • You can write computer programs that perform the mundane repetative tasks for you.

      • You can write computer programs to automate some of your daily tasks

      • Etc. etc.

Example "home-brewed" computer application

  • Suppose you want to find the most commonly used word in some document....

    name = input('Enter file:')
    handle = open(name, 'r')
    counts = dict()
    
    for line in handle:
        words = line.split()
        for word in words:
            counts[word] = counts.get(word, 0) + 1
    
    bigcount = None
    bigword = None
    for word, count in list(counts.items()):
        if bigcount is None or count > bigcount:
            bigword = word
            bigcount = count
    
    print(bigword, bigcount) 

DEMO: Progs/words.py --- use words.txt as input file