Python SF19PB1 Homework

  1. Tuesday, August 13, 2019: up to Standard output in the in-class examples. Read ahead from there to see what we’re doing on Thursday. Install Python 3.7.4 and IDLE on your Mac or PC. (Microsoft PC people: what do I need to update in my installation instructions? Thanks.) Try out everything we did in class and see if it actually works as advertised. (Do this each day.) Don’t worry too much about try and except: we can go over them again in the future.

    Read the course’s grading policy. Bookmark the Python documentation and the course home page in your browser. Look at the documentation for the built-in functions we mentioned in class tonight: round, len, int, print, input, etc. The Python round function is implemented in the language C.

    Create a GitHub account if you don’t already have one. To add a photo of yourself to your GitHub account, pull down the triangle in the upper right corner, select Settings, and upload a picture. Please email me (at mark.meretzky@gmail.com) your name and the name of your GitHub account. Then admire the other students’ GitHub accounts.

    Here is the instructor’s GitHub account and his WS19PB02-MarkMeretzky organization left over from a previous semester. The organization contains a repository named flag, and the repository contains a file named flag.py. This file is a Python script and we’ll talk about it here.

    Three differences between Python 2 and Python 3 we mentioned tonight (see Common Stumbling Blocks):

    1. In Python 2, the / operator gave you a truncated quotient. In Python 3, the / operator gives you a quotient that is not truncated.
    2. In Python 2, print was a statement and needed no parentheses. (I actually didn’t mention this.) In Python 3, print is a function and therefore needs parentheses.
    3. In Python 2, the input function was named raw_input. (To make matters worse, Python 2 also had another function named input.)
  2. Thursday, August 15, 2019: up to while loops in the in-class examples.

    Complete your installation of Python on your Mac or PC by running the Install certificates.command which is alongside IDLE in the Python 3.7 folder. Then uncomment (i.e., remove the # from) the print in line 54 of ibm.py in exit status and see if you print the current price of IBM stock. Also uncomment the print in line 68 of temperature.py and see if you print the current temperature in fahrenheit in New York City.

    Create a GitHub organization named SF19PB1-yourname (with a dash), where yourname is your GitHub loginname. Follow these instructions. We will use a GitHub organization as a container to contain our repositories. Each repository will contain one Python program.

  3. Tuesday, August 20, 2019: up to the Thruway example in for loops in the in-class examples. Write an interesting Python program using words such as input, print, while, for, range, etc. Create a repository in your Python organization (follow these instructions) and copy your interesting program into the repository. Then admire the other students’ repositories.
  4. Thursday, August 22, 2019: up to exercise #3 in Pi in the in-class examples. Hand in the graph paper program, and another interesting Python program. As usual, you hand in these programs by uploading each program to a GitHub repository in your GitHub organization. Then admire the programs of the other students.

    Yes, IDLE has a debugger. “Still incomplete and somewhat experimental.”

  5. Tuesday, August 27, 2019: up to exercise 11 in Index. We also looked at the answers. I added a red and white table with 260 lines to Tkinter; hope this is helpful.

    Write an interesting Python program using the stuff we’ve been covering in class. I like programs that draw pictures. If your program counts through a series of integers, do it with a for loop, not a while loop. You could time how long the program (or the non-interactive part of the program) takes to run. Save the program in a file whose name ends with .py. Upload this file to its own GitHub repository in your SF19PB1 organization. You get no credit for programs that are not uploaded to your SF19PB1 organization.

  6. Thursday, August 29, 2019: up to exercise 1 of Pig Latin in the in-class examples. Study very carefully how I changed your programs in the answers. Write an interesting Python program using the stuff we’ve been covering in class, and upload it to its own GitHub repository in your SF19PB1 GitHub organization.
  7. Tuesday, September 3, 2019: up to URL in the in-class examples. Study very carefully how I changed your programs in the answers. Write an interesting Python program using the stuff we’ve been covering in class, and upload it to its own GitHub repository in your SF19PB1 GitHub organization. For example, loop through the lines in the text file
    /Library/Frameworks/Python.framework/Versions/3.7/share/doc/python3.7/examples/Tools/pynche/X/rgb.txt
    on your Mac, and display the colors as we did here.
  8. Thursday, September 5, 2019: up to Loop in the in-class examples. Write something interesting. For example, your Python program could read in the file
    /Library/Frameworks/Python.framework/Versions/3.7/share/doc/python3.7/examples/Tools/pynche/X/rgb.txt
    and display the colors in a tkinter list or menu. Or you could read in an image file and make the colors lighter (by increasing the red/green/blue numbers) or darker (by decreasing the red/green/blue numbers), or turn the contrast up or down. Or you could superimpose two photographs. How about Donald Trump and …? Could you figure out how to write a Python program that plays an audio file? Your Mac already has audio files in the folder
    /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/test/audiodata
    You might have to install a new module using pip3 install).
  9. Tuesday, September 10, 2019: up to Zip in the in-class examples. Write something interesting and upload it to a new repository in your SF19PB1 organization. Can you print the lyrics to Gangnam Style? Are you interested in any of the statistical stuff in the statistics module? What was the (meaning and) purpose of the [:,:,1] we saw today in the code that changed the color image to black and white? I put a list of audio files into Loop. Can you make a jukebox? JC claims you can train this Python package to recognize images of dogs.
  10. Thursday, September 12, 2019: up to Sort in the in-class examples. Write something interesting and upload it to a new repository in your SF19PB1 organization. For example, look at the documentation for the matplotlib in Barchart. Can you do speech recognition? Experiment with Colaboratory.
  11. Tuesday, September 17, 2019: up to List comprehension in the in-class examples. Write something interesting and upload it to a new repository in your SF19PB1 organization. For example, a pie chart with matplotlib.pyplot, sorting, List comprehension. Be sure to refresh the web pages.
  12. Thursday, September 19, 2019: up to CSV database in the in-class examples. Download an interesting New York City database to your Mac in CSV format. Write a Python program that will read this file and output some stuff, either with calls to the print function, or as a bar chart or pie chart, or spoken out loud. “You don’t want to walk in this neighborhood because…”
  13. Tuesday, September 24, 2019: up to Higher order functions in the in-class examples. For the restaurant with the most mouse violations, see Counter.

    Find a database whose records contains fields for latitude and longitude. (An example is Street Trees.) Write a Python program that will read the database from the web in CSV format and display some or all (probably only some!) of the records as pins in a Google map. Include a link to the map in the docstring at the start of the Python program when you upload the program to your GitHub organization.

  14. Thursday, September 26, 2019: up to Roman in the in-class examples. If you want to learn to program in Python, you should write code to determine if the b in the first program in Tic already contains a winning position, and, if so, who the winning players are. You should also do the two exercises in Plot. (Even better, change the column of Ss and Ps to a column of Trues and Falses.) You should write a Python program that reads an online CSV database if you have not already successfully done so.
  15. Tuesday, October 1, 2019: up to Two parallel columns in the in-class examples. Write something interesting, probably involving tuples, dictionaries, and/or lists of lists (or tuples of tuples).
  16. Thursday, October 3, 2019: up to Counter in the in-class examples. Be sure to refresh each web page before you look at it. If the Downloads page offers a version of Python newer than 3.7.4, download and install it. Write something interesting with dictionaries.
  17. Tuesday, October 8, 2019: up to Environment in the in-class examples. Be sure to refresh each web page before looking at it. For example, in Environment on the new macOS Catalina 10.15, the environment variable SHELL now contains /bin/bash in a Python program run in IDLE, and /bin/zsh in a Python program run in the Terminal window. Why two different shells? And I simplified (or at least localized) the creation of the sorted lists years and races in infant mortality. Write something interesting, probably with dictionaries.
  18. Thursday, October 10, 2019: up to Download JSON in the in-class examples. Refresh each web page before looking at it. Make sure you can write a Python program that displays the current temperature, air pressure, humidity, wind speed and direction, etc.; the current time, sunrise, sunset (in a human-friendly format), and the icon. Then do something interesting. It’s okay if you want to use pandas. Look at the pandas examples I added to Counter, Restaurant inspection, and Street trees.
  19. Tuesday, October 15, 2019: up to Test for membership in the in-class examples. I asked Juan Carlo Banayo to upgrade the Macs in room 8149 to Python 3.8.0. Install Python 3.8.0 on your Mac at home. Then do something interesting.
  20. Thursday, October 17, 2019: up to Intersection in the in-class examples. When we ran out of time today, we were looking at the two ways of using max in exercise 2 of Intersection. To clarify this, I added some max examples here. I have a working example of where.

    Make sure you understand groupby one column before you try to understand groupby two columns. Then write something interesting, probably using sets, dictionaries, DataFrames, and/or Series.

    See the new exercise 4 in Download JSON. At 8:00 a.m. EST, it’s daytime in New York and nighttime in Seattle:

  21. Tuesday, October 22, 2019: up to Pass list in the in-class examples. We also did pandas where. Compare weather.py with exercise 4 in Download JSON. See the simple itertools.combinations example I added to Limitations. Do something interesting, probably involving a function definition. Note that by the end of the course I will have asked you to write and upload to GitHub approximately 30 python programs; your grade depends on these 30 programs.
  22. Thursday, October 24, 2019: up to Pass list in the in-class examples. Make sure mypy works on your Mac. Can we configure IDLE so that it always feeds your Python program to mypy before running the Python program? See the environment variable $IDLESTARTUP in Startup and code execution. Write something interesting involving functions.
  23. Tuesday, October 29, 2019: up to Class Date in the in-class examples. Study how to attach an attribute to an object. Write and upload something interesting.
  24. Thursday, October 31, 2019: we did a review of for loops, dict, collections.defaultdict, collections.Counter, and max with a lambda function. Write and upload something interesting, probably involving attaching attributes to an object.
  25. Tuesday, November 5, 2019: up to Class Date in the in-class examples. Write a class that has (at least) the methods __init__ and __str__. The __init__ method should store one or more attributes into the newborn object. (How about firstName and lastName? Or temperature, humidity, and windspeed? Or bust, waist, and hip?) Then create several objects, call the __str__ method of each object, and print the return value of each call to the __str__ method.

    The course in room 8110 is CCNA (Cisco Certified Network Associate). Its teacher says that networking uses a lot of Python.

  26. Thursday, November 7, 2019: up to Class Date in the in-class examples. Do all the exercises in Class Date and upload the resulting class Date to your GitHub organization.
    pip3 search jupyter
    jupyter (1.0.0)                               - Jupyter metapackage. Install
                                                    all the Jupyter components in
                                                    one go.
    
    pip3 install jupyter
    jupyter --version
    jupyter --help
    
  27. Tuesday, November 12, 2019: up to decimal in the in-class examples. As usual, write something interesting. But package it as one or more functions and/or classes, and package them module. For example, the classes date, time, and datetime in the Python Standard Library are packaged in the module datetime. Also write a Python program that imports your module.
  28. Thursday, November 14, 2019: up to Iterator in the in-class examples. Study the MyRange, FloatRange, and week.range examples in that page. Then create an interesting iterable. I checked, and yes, the pandas Series and DataFrame are both iterable.
  29. Tuesday, November 19, 2019: up to Generator expressions in the in-class examples. Write an iteresting program with a list comprehension. Then rewrite it with a generator function, and then rewrite it again with a generator expression.
  30. Thursday, November 21, 2019: