CSE 142: Computer Programming I, Autumn 2008 |
CSE Home | About Us Search Contact Info |
The following students wrote awesome Python games:
The assignment: Turn in a file named mygame.zip
containing a Python game of your own creation written in Pygame. Your game can be anything you want, but we have two suggestions if you don't have an idea of your own:
You may choose to recreate the Monty Hall game according to the specifications provided or come up with your own. Look toward games listed on pygame.org for inspiration, but no stealing code! If you want to do a Breakout game, Pygame's web site has several Breakout-style games you can run or look at for inspiration.
The reward for turning in this program is 1 extra late day for use on your normal Java programs, plus a spot on the course web site's wall of fame, where every game will be posted so that everyone else can be jealous that they didn't come learn Python this quarter.
The assignment: Turn in files named birthday.py
and date.py
containing a Python version of your program from the Java Homework 8, which will be posted tomorrow. (We're calling it "HW8" and skipping HW7 to be consistent with the Java numbering.) Write a Date
class with the following behavior:
days_in_month
method to return the number of days in a Date
object's corresponding monthnext_day
method to advance a Date
by 1 day__str__
method to convert a Date
into a string
For an extra challenge, make your Date
objects store not only a month and day but also a year. Modify the Date object to have a year field, to accept a year parameter to the constructor, to return the year as part of the __str__
output, and so on. Use this in your client program to read today's month/day/year and your birthdate's month/day/year and reporting how many total days old the person is. To this, count days from their date of birth until today. Don't forget that leap years (ones divisible by 4) have 366 days, which should be accounted for in your days_in_month
method.
What is today's month? 11 What is today's day? 17 What is today's year? 2008 What is your birthdate's month? 9 What is your birthdate's day? 19 What is your birthdate's year? 1979 There are 30 days in month #9 Your birthday 9/19 is in 307 days. You are 10665 total days old.
In either form, the reward for turning in this program is 1 extra late day for use on your normal Java programs, and +1 charisma and 2 saving throws. (Since it's the end of the quarter, getting extra late days is less motivating than it used to be. Mostly you'd just be doing this one for the learning experience.)
The assignment: Turn in a file babynames.py
containing a Python version of your program from Homework 6. The screenshot below shows the output when run with the name "Lisa". As a reference, our sample solution is 80 lines long. In order to display data in a similar font to the Java program, you'll have to pass some extra parameters when calling your panel's create_text
method, including setting its anchor
parameter to "sw" for Southwest and setting its font
parameter to a ("SansSerif", 12) tuple, such as:
panel.canvas.create_text(0, 18, text="Hello there!", anchor="sw", font=("SansSerif", 12))
Your image doesn't have to match ours pixel-for-pixel to get the credit. If you want an extra challenge, modify your output to produce a line graph rather than a bar graph, as shown in the following image. Hint: You can achieve this by storing all points into a list of form [x1, y1, x2, y2, ...] and passing this list as a parameter to create_line.
The reward for turning in this program is 1 extra late day for use on your normal Java programs, plus eternal good looks, and overall excellent karma. (Since it's the end of the quarter, getting extra late days is less motivating than it used to be. Mostly you'd just be doing this one for the learning experience.)
The assignment: Turn in a file guessinggame.py
(lowercase) containing a Python version of your program from Homework 5. Change your haiku intro message into a haiku about Monty Python. As a reference, our sample solution is 55 lines long.
The reward for turning in this program is the usual 1 extra late day for use on your normal Java programs, plus a Facebook snake icon, eternal good looks, and overall excellent karma.
The assignment: Turn in a file grades.py
(lowercase g) containing a Python version of your HW4 Grades program, producing the same output except for the following differences:
This program reads your scores on homework and exams and reports your course grade or what score you need on the final exam. Exam 1 weight? 20 Exam 2 weight? 30 Homework (weight 50): Number of assignments? 3 Assignment 1 score? 14 Assignment 1 possible? 15 Assignment 2 score? 17 Assignment 2 possible? 20 Assignment 3 score? 19 Assignment 3 possible? 25 Sections attended? 5 Section points = 15 / 20 Total points = 65 / 80 Weighted score = 40.6 Exam (weight 20): Score? 78 Curve? 3 Total points = 81 / 100 Weighted score = 16.2 Have you taken the final? (y/n) y Exam (weight 30): Score? 95 Curve? 10 Total points = 100 / 100 Weighted score = 30.0 Course grade = 86.8
The rewards you'll get for turning in this program are the following:
The assignment: Turn in a file circles.py
(lowercase c) containing a Python version of your HW3 Circles program that produces the output shown below, essentially the same as the Java version but drawn in Python. The window size and coordinates of all drawn figures are the same as in the Java version. As a reference, our sample solution is 40 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.
You won't be able to check your output since our Python DrawingPanel doesn't know how to compare images. But we will be lenient on whether the graphical output exactly matches. If you like, you can play around a bit with the exact colors and coordinates to produce a figure you like better, so long as the overall appearance closely matches the above screenshot.
Producing the above output will count for full credit, but if that sounds too easy for you and you want an added challenge, you can instead make your circles.py
program produce the output below, drawing "globe" figures instead of the normal target figures. This is harder, but probably not as hard as it looks! Read below to see how to do it.
The main change between this globes program and the Java Circles version is that rather than drawing concentric circles in each subfigure, this version draws two sets of contentric ovals that give each subfigure a "globe-like" appearance. 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" from the Java HW3-Circles assignment. The dimensions and counts for this assignment are identical to those of the Java HW3 assignment.
The other change from the Java program is that the colors of each subfigure and grid have been parameterized. Use string parameters to represent the colors used in the screenshot, such as orange (top-right), red (bottom-middle), and blue (bottom-right). Use default parameter values and/or parameter keywords as appropriate.
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 rewards you'll get for turning in this program are the following:
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 rewards you'll get for turning in this program are the following:
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.
In addition, Python is used in a lot of other fields and disciplines, so it can be useful to have experience in it. Lastly, Python is a powerful language that does a lot of things more easily than Java, so it can be fun rewriting your past Java programs in Python and seeing how much shorter and cleaner they can be solved.
Our Python program will be hosted by some of our TAs, Kimberly Todd, Kevin Wallace, and Ian Gienger, under Marty's advisement. Each week, they will hold a 50-minute 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 entirely optional. The reward for doing these projects will be small, to make sure that these sessions don't give students with prior experience an unfair advantage over new programmers. Right now, we're planning to reward students with 1 free late day for each Python program submitted. 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 given out for that week. If you finish it, you can turn it in from a link that we'll put at the top of this page.
If you want to install and run Python programs on your own computer, follow our Python Installation Instructions below:
Yes! If you miss the session, feel free to look at each week's slides and code that we post, and/or still submit the program. And even if you come to the sessions, you don't have to work on the programs we give out; if you just want to come to the sessions and that's all, that is fine with us. It's up to you.