[an error occurred while processing this directive]

CSE 142 Python Program

Python session time/place: Tuesdays, 3:30 - 4:20pm, in MOR 220

Week 9 (classes, objects)

Week 8 (SAGE)

Week 7 (file processing, lists)

Week 6 (review, file IO)

  • Lecture Slides: ppt ppt, pdf pdf
  • py stats.py
  • py remove_lowercase.py
  • If you missed any of the python lectures in the past and you still would like to learn, then come to the python lecture this week. We will be reviewing all of the old material as well as introducing some new things.

  • Python Homework 6: You Choose
    Due Tuesday, November 17, 11:30pm. Turn in Python HW6 here.

    The assignment: Turn in one of the previous homework assignments if you didn't get a chance to before. The reward for this program is 1 extra late day. Instructions: for you first file, name it review.py. Any subsequent homeworks should have the name of the assignment such as song.py or guessing_game.py.

Week 5 (random, while loops and tuples)

  • Lecture Slides: ppt ppt, pdf pdf
  • Python Homework 5: Guessing Game
    Due Saturday, November 7, 11:30pm. Turn in Python HW5 here.

    The assignment: Turn in a file guessing_game.py containing a Python version of your HW5 guessing game program. The reward for turning in this program is 1 extra late day for use on your normal Java programs.

    For an extra challenge: implement a two-dimensional guessing game, still named guessing_game.py, according to these specifications.

    The program will 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: 5
    Guess y: 7
    You're cold. Go south east
    Guess x: 18
    Guess y: 5
    You're cold. Go south west
    Guess x: 15
    Guess y: 2
    You're warm. Go north west
    Guess x: 12
    Guess y: 3
    You're hot! Go north west
    Guess x: 11
    Guess y: 4
    You got it right in 5 guesses!
    
    Overall results:
    Games played  = 1
    Total guesses = 5
    Guesses/game  = 5.0
    

    More sample output:

    Test 1 | Test 2 | Test 3 | Test 4 | Test 5

Week 4 (If/Else, Logic, Strings)

  • Lecture Slides: ppt ppt, pdf pdf
  • py substitute.py
  • Python Homework 4: Birthday
    Due Sunday, November 1, 11:30pm. Turn in Python HW4 here.
    No late turnins accepted.

    The assignment: 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 October267 - 296
    Scorpio 24 October - 22 November 297 - 327
    Sagittarius 23 November - 21 December328 - 355
    Capricorn 22 December - 20 January 356 - 365 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.

    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 >>
    

Week 3 (parameters, return, math, graphics, parameters)

  • Lecture Slides: week3.pdf | week3.ppt
  • drawingpanel.py
  • car.py
  • Python Homework 3: Circles
    Due Sunday, October 25, 11:30pm. Turn in Python HW3 here.
    No late turnins accepted.

    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.

    circles output

    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.

    globes output

    globe lines globe lines 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.

  • List of all Python color names
  • Visual index to the Python colors

Week 2 (Expressions, for Loops, Constants)

  • Lecture Slides: ppt ppt , pdf pdf
  • expressions.py
  • mirror.py
  • mirror2.py
  • Python Homework 2: Space Needle
    Due Saturday, October 17, 11:30pm. Turn in Python HW2 here.
    No late turnins accepted.

    The assignment: Turn in a file ascii.py (lowercase a) containing a Python version of your HW2 Space Needle program or last quarter's Rocket Ship program, producing the same output. As a reference, our sample solution is 35 lines long for the space needle with comments. The reward you'll get for turning in this program is 1 extra late day for use on your normal Java programs.

Week 1 (Basics, Functions)

  • Lecture Slides: ppt ppt , pdf pdf
  • Python Installation Instructions
  • Python Official Website
  • Python Homework 1: Song
    Due Saturday, October 10, 11:30pm. Turn in Python HW1 here.
    No late turnins accepted.

    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 you'll get for turning in this program is 1 extra late day for use on your normal Java programs.


General info about the CSE 142 Python program:

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.

What 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.

Why would I want to learn Python, in addition to Java?

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.

Who will run these sessions? Where will I go, and what will I do?

Our Python program will be hosted by some of our TAs, under the advisement of the instructor. 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:

  • Going to the weekly sessions
  • Completing optional Python programming exercises each week, as desired

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.

What reward do I get for doing this? Do I have to do it?

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.

How do I participate or learn more?

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:

Can I still participate even if I don't go to the sessions or cannot make it to the sessions? Can I still come to the sessions even if I don't want to turn in the weekly Python programs?

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.

[an error occurred while processing this directive]