These are optional assignments you can do each week to help increase your understanding of Python. Each assignment you do will earn you +1 free late day that you can use on your Java homework.
Write a game of your choosing with the help of the pyGame library. It can be any game you want, as long as it is your own work and isn't basically the same as one of the examples we wrote in our Python session. Though games can be very fancy and complex if you want them to be, your submission can be something simple and straightforward if you prefer.
game.zip
that you will turn in.Since it is the end of the quarter, it doesn't really make sense to try to reward you with a late day for 142. So if you are bold enough to write a pyGame, if you're going on to CSE 143 next quarter, we will reward you with +1 free late day in CSE 143, Winter 2012! That's right, it's the first ever cross-course assignment reward. If you're not going on to 143, the best we can offer you is a hearty "kudos", and we can post your name and a link to your game here on this web page if you like, so that other students can check it out.
Do a new object-oriented assignment that practices today's material on Python classes and objects. There will be two files to turn-in. The first is a file named date.py
that implements a class Date
, where each Date
object represents a single calendar month/day date such as September 19. Each Date
object should have the following behavior:
days_in_month
method to return the number of days in that Date
object's month.next_day
method that changes the state of the Date
by advancing it 1 day in time. For example, the next day after 9/19 is 9/20; the next day after 9/30 is 10/1; and the next day after 12/31 is 1/1__str__
method to convert the Date
into a string such as "9/19"
.
For example, it should be possible to use the Date
class in the following way at the interpreter:
>>> d = Date(9, 29) >>> d.month 9 >>> d.day 29 >>> d.days_in_month() 30 >>> d.next_day() >>> d.month 9 >>> d.day 30 >>> d.next_day() >>> d.month 10 >>> d.day 1 >>> d.days_in_month() 31 >>> str(d) # calls __str__ '10/1' >>> d.next_day() >>> str(d) # calls __str__ '10/2'
The second file to submit is called birthday2.py
. This file should be a client program that uses your Date
objects to find out how many days it is until the user's next birthday. The following is a sample run of the birthday2
program:
Please enter today's date: What is the month? 7 What is the day? 24 Please enter your birthday: What is the month? 11 What is the day? 6 Your next birthday of 11/6 is in 105 day(s).
Notice that this version of the program doesn't print the absolute day of the year for today or the birthday. You should figure out how many days it is until the user's birthday in a different way. Starting from today, if you walk forward in time until the user's birthday, one day at a time, counting how many steps you took, you'll know how many days it is until the user's next birthday. You don't need to handle the "birthday is tomorrow" case this time; just either print Happy Birthday! or print how many day(s) until the next birthday.
If you want to try out some of Python's other object features, try overloading some operators in your Date
class. For example, make it possible to compare dates by implementing a <
operator.
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.)
You should include the following import
statement in your final product. Importing the os
modile will let us check to see if files exist.
import os
The os.path.exists
method will return True
if a file with a given name exists within the working directory.
name = input("Input file name: ") if os.path.exists(name): ...
Turn in a file randomwalk.py
that contains a Python version of your HW5 RandomWalk Java program. Or...
Turn in a file guess2d.py
containing a Python guessing game program. In this program you should implement a two-dimensional guessing game that thinks of a random 2-D (x, y) point using integer coordinates somewhere between (1, 1) and (20, 20) inclusive. The user tries to guess the point until getting it right. When the user makes a wrong guess, give a hint of "cold" if the distance from the user's guess to the right point is > 5.0, "warm" if the distance is 1.5 - 5.0 inclusive, and "hot" if the distance is < 1.5. Also tell the user which direction to go to find the right answer using directions like "north" (positive Y) and "east" (positive X). The output should look like this:
This program is a 2-D guessing game. I will think of a point somewhere between (1, 1) and (20, 20) and give hints until you guess it. Guess x/y: 5 7 You're cold. Go south east Guess x/y: 18 5 You're cold. Go south west Guess x/y: 15 2 You're warm. Go north west Guess x/y: 12 4 You're hot! Go west Guess x/y: 11 4 You got it right in 5 guesses!
Turn in a file birthday.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.
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 - 49 |
Pisces | 19 February - 20 March | 50 - 79 |
Aries | 21 March - 20 April | 80 - 110 |
Taurus | 21 April - 21 May | 111 - 141 |
Gemini | 22 May - 23 June | 142 - 174 |
Cancer | 24 June - 22 July | 175 - 204 |
Leo | 23 July - 23 August | 205 - 235 |
Virgo | 24 August - 22 September | 236 - 266 |
Libra | 23 September - 23 October | 267 - 296 |
Scorpio | 24 October - 22 November | 297 - 327 |
Sagittarius | 23 November - 21 December | 328 - 355 |
Capricorn | 22 December - 20 January | 356 - 365 and 1 - 20 |
The following is an example output from your program:
This program tells you how many days it will be until your next birthday. Please enter today's date: What is the month (1-12)? 7 What is the day (1-31)? 24 7/24 is day #205 of 365. Please enter your birthday: What is the month (1-12)? 11 What is the day (1-30)? 6 11/6 is day #310 of 365. Your next birthday is in 105 days. You are a Scorpio. << your sign's fact or horoscope here >>
Turn in a file illusion.py
(lowercase i) containing a Python version of your HW3 Illusion 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.
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.
Turn in a file song.py
or spaceneedle.py
(all lowercase) containing a Python solution to this course's HW1 Song or HW2 Space Needle program, respectively, producing the same output. (You can do both if you want, but you will not receive double credit.)