Welcome to introduction to Python!
This three week class will prepare you to read and write basic python scripts. No prior programming experience required!
Email eric.schles@gsa.gov
Some homework assignments are from hackerRank. There are a few reasons for this:
Introduction to Python - Class 1 (class time 30 minutes) - CLASS ONE NOTES
.format
operator.Standing on the shoulders of giants - Class 2 (class time 45 minutes) - CLASS TWO NOTES
Homework:
For this assignment you will be either creating an account on https://www.pythonanywhere.com or downloading and installing Python locally. If at all possible, it is better to install python locally.
But if you are restricted from doing so, PythonAnywhere works.
The program should create a file called practing_file_writing.txt. The file should contain the following text:
Hello! You've successfully created this file with a program! Congradulations!!!!
The program should open practicing_file_writing.txt and then add the following line to the end of the file:
Sincerely, Python
So the whole file should now look like:
Hello! You've successfully created this file with a program! Congradulations!!!! Sincerely, Python
The file should then be writen back out as practicing_file_updating.txt.
Week 2
Introduction to Python Data Structures - Class 1 (class time 30 minutes)
More file processing - Class 2 (class time 45 minutes)
Write a program called traversal.py - This file will traverse the entire file system, starting at the first directory you give it.
Write a new program called print_traversal.py - this file will traverse the entire file system, starting at the first directory you give it and print out the full paths of every filename it traverses.
Write a new program called print_analyze_traversal.py - this file traverse the entire file system, starting at the first directory you give it and print out the full paths of every filename it traverses. Also it will record the number of times the file is a python file and the number of times it is not. At the end of the program, the program should print out how many python files were found and how many non-python files were found. It should print this out in absolute terms and relative terms. Example:
total number of python files found: 5 total number of non-python files found: 500 percentage of python files: 1% percentage of non-python files: 99%
Week 3
Introduction to methods - Class 1 (class time 30 minutes)
Making use of methods on strings with files (class time 45 minutes)
Now that you have an understanding of how to iterate over a set of things, let's make use of that to really do something interesting!
How you'll call the file: python find.py dir_name
Now you'll be creating a new program called find_replace.py. This program will do the same traversal as the last program, except, it will also open any files with Hello there! edit that line to say Hi instead of Hello there! and close the file, writing it back out to the file system.
Now you'll be going even further - now instead of looking for a simple find and replace, you'll be adding descriptive statistics to any files you find. The descriptive statistics you'll be adding are:
the number of lines in the file
the five most commonly used words in the file
if the file is a program, what language is it written in
Note you should write functions for each of these sub commands. Here's what a typical output should look like:
This file has 10 lines The five most common words used are: print, if, else, import, and This file is written in Python