Our Python sessions are every Thursday, 3:30 - 4:20pm, in EEB room 125. For those of you who were unable to make it to the first section, we would still like to see you at the next one! If you are interested and have not yet provided us with your email, you should contact Paul or Ryan and we will add you to our email list. We will use this to notify everyone about error corrections, things we forgot to mention, etc.
The assignment: Turn in a file personality.py
containing a Python program that produces the output and behavior of the Java HW#6 Personality Test. You are free to use anything that has been covered in the Python section, including map and lambda. However, these are not required.
The assignment: Turn in a file babynames.py
containing a Python program that produces the output and behavior of the Java HW#6 Baby Names. For this assignment, use the following modified versions of the names.txt input file that separate the name from the rankings by a colon. (We're using these modified versions because they are more conducive to tokenizing with Python's split
function.)
Sample output
The assignment: Turn in a file slither.py
containing a Python program that produces the output and behavior of the Java HW#5 Random Walk. Additionally, you will be making your Random Slither turn different shades of green as it slithers across the screen. You will do this by creating a custom color. This is done by creating an red-green-blue (RGB) tuple and converting that tuple into a string that Tkinter (the graphical tool that the drawing panel takes advantage of) recognizes. For example, we may want the color yellow, then the RGB tuple would be (255, 255, 0). After making that color we can produce the string we want and draw a shape.
hexColor = "#%02x%02x%02x" % (255, 255, 0)
g.create_circle(100, 100, 200, 200, fill=hexColor)
You will use this same concept to create a green slitherer. Your slitherer should start at green (0, 255, 0). With each step, you should change the color of the slitherer. This will be done by randomly choosing whether to increase the green value in your RGB tuple by one, or decrease it by one.
Note: RGB values must be within the range of 0-255 inclusive. This means that if you increment from 255, the new value should be 0. If you decrement from 0, the new value should be 255. For example, the slitherer will start out at RGB (0, 255, 0). After the first step, it will randomly decide whether to increase or decrease the green value resulting in one of two options: (0, 254, 0) or (0, 0, 0). Assume it decided to decrement by 1. After the following step, it would randomly choose between incrementing and decrementing the green value and could result in either: (0, 253, 0) or (0, 255, 0).
Sample output
The assignment: Turn in a file birthdays.py
containing a Python program that produces output such as the output below. The task is identical to the Java HW4 except that you will also print out the user's astrological sign such as Leo or Virgo. At the bottom of your program, you should print an interesting fact about your own astrological sign, or your sign's current horoscope. As a reference, our sample solution is 106 lines long. Check here to find the date ranges for each sign. Or look at the following table:
Sign | Date Range | Absolute Day Range |
---|---|---|
Aquarius | 21 January - 18 February | 21 - 50 |
Pisces | 19 February - 20 March | 51 - 81 |
Aries | 21 March - 20 April | 82 - 112 |
Taurus | 21 April - 21 May | 113 - 143 |
Gemini | 22 May - 23 June | 144 - 176 |
Cancer | 24 June - 22 July | 177 - 205 |
Leo | 23 July - 23 August | 206 - 237 |
Virgo | 24 August - 22 September | 238 - 267 |
Libra | 23 September - 23 October | 268 - 298 |
Scorpio | 24 October - 22 November | 299 - 328 |
Sagittarius | 23 November - 21 December | 328 - 357 |
Capricorn | 22 December - 20 January | 358 - 366 and 1 - 20 |
The following is an example output from your program. Notice that for simplicity, the month and day are read on separate lines.
Today is 1/29/2008, day #29 of the year. Person 1: What month were you born? 10 What day were you born? 17 10/17/2008 falls on day #291 of 366. Your next birthday is in 262 day(s). Your sign is Libra. Person 2: What month were you born? 11 What day were you born? 23 11/23/2008 falls on day #328 of 366. Your next birthday is in 299 day(s). Your sign is Sagittarius. Person 1's birthday is sooner. << your sign's fact or horoscope here >>
The assignment: Turn in a file globes.py
(lowercase g) containing a Python version of your program that produces the same output as globes.png below. As a reference, our sample solution is 35 lines long. The reward for turning in this program is 1 extra late day for use on your normal Java programs, plus a super cool snake icon on your Facebook profile, if you use our Facebook application.
Hint: The globes are created by using two sets of "rounded lines" - one set is vertical, the other horizontal. These are actually drawn using two sets of ovals. In one set, all ovals have equal heights but varying widths. The other set have equal widths and varying heights. In both cases, the amount of change in oval size is the same as the "gap" concept from the Java HW3-Circles assignment. The dimensions and counts for this assignment are identical to those of the Java HW3 assignment.
The assignment: Turn in a file spaceneedle.py
(lowercase s) containing a Python version of your HW2 Space Needle program, producing the same output. The program should use any feature of Python that you have seen so far to simplify the program. As a reference, our sample solution is 35 lines long. The reward for turning in this program is 1 extra late day for use on your normal Java programs, plus a super cool snake icon on your Facebook profile, if you use our Facebook application.
The assignment: Turn in a file song.py
(lowercase s) containing a Python version of your HW1 Song program, producing the same output. As a reference, our sample solution is 65 lines long. The reward for turning in this program is 1 extra late day for use on your normal Java programs, plus a super cool snake icon on your Facebook profile, if you use our Facebook application.
This quarter in CSE 142, we will conduct a special optional program to offer students a chance to learn a second programming language as you're learning Java. The second language's name is Python.
Python is a language that's good for writing programs to process text and other data. It's used heavily in the Linux operating system and at companies like Google.
Learning two programming languages is a bit like growing up in a bilingual family: you'll not only learn those two languages well, but you may also learn some higher concepts about programming and programming languages in general.
To start using Python on your own machine, follow the Python Installation Instructions. The Python Website i s a great place to begin learning the basics.
Our Python program will be hosted by two of our TAs, Paul Beck (paulbeck AT cs.washington.edu) and Ryan Tucker (rctucker AT cs.washington.edu). Each week, they will hold a 1-hour session to teach you the equivalent of that week's Java course material into Python, along with any related issues.
The work involved in this program would be the following:
Primarily, these projects will consist of solving the same problem as that week's Java programming assignment, but in Python, and perhaps with minor modifications to the assignment spec.
Participation is purely optional. The reward for doing these projects would be small; right now, we're thinking of rewarding these students with 1 free late day for each Python program completed. No grade points will be added or subtracted in any way for participating in this project.
Just go to the next Python session at the time listed above, and if you find it interesting, try writing the Python program. If you finish it, you can turn it in from a link that we'll put at the top of this page.