UNIVERSITY OF MICHIGAN SCHOOL OF INFORMATION Assignment 2 – Writing some Python Due Date: Friday January 22, 2009 at 9:00PM The purpose of this exercise is to get you writing small Python programs. You will write five programs for this assignment: • Exercise 1.4: Using Python as a Calculator • Exercise 2.3: Welcoming the User • Exercise 2.4: Computing Pay • Exercise 3.1: Computing Pay with Overtime • Exercise 3.3: Computing Grades None of the programs require any iteration. When the sample output in the book shows the user entering data several times -‐ you simply re-‐run the program by typing "python prog.py" repeatedly. For each of the exercises, you will hand in a screenshot of the program running correctly in the command line or terminal window and the source code. Since exercise 1.4 is using Python as an interpreter, there is no source code to hand in. Sample screen shots are shown at the end of the assignment. There are several pre-‐requisites for the assignment to get the Python software and text editor installed on your system. The pre-‐requisites are necessary for the assignment -‐ but they are not graded -‐ you are welcome to get as much help as you need fro anyone you like when it comes to getting your text editor installed and Python installed and have everything set up so you can use Python and write programs. Pre-‐Requisite One: Getting Software Installed and Using Python Work through the installation instructions at: http://www.pythonlearn.com/install.php There are instructions for installing Python, Installing your text editor, and writing a simple first program. There are detailed screen casts which walk you through everything click for click up to and including using the text editor to create your program and using the command or terminal window to run your Python program. The screen casts are less than 10 minutes and are well-‐worth your time to watch. There is nothing to hand in for this step – you just need to be comfortable with editing files, making directories, and running Python programs before you continue. Make sure that you following the instructions set your text editor to replace tabs with spaces. You only need to do this once and then your editor remembers it forever. If you do not do this, you may experience unending frustration when your program looks perfect but fails with an unexplainable "indentation error". NotePad++: Settings -‐> Preferences -‐> Language Menu/Tab Settings TextWrangler: TextWrangler -‐> Preferences -‐> Editor Defaults Pre-‐Requisite Two: Learning How to Make Screen Shots Many of the assignments in the course will require you to take screen shots of your running programs or the source code of your programs. There is a handout in the course site describing how to take screen shots on your system titled, "Taking Screen Shots". There is also a set of screen cast videos that walk you through the act of taking screen shots on each of the operating systems (XP, Vista and Macintosh). http://tinyurl.com/l8lvdh (Windows Vista) http://tinyurl.com/mldueb (Windows XP) http://tinyurl.com/mp29ab (Macintosh) You should practice taking a few screen shots and making files. General Guidance These three programs are pretty simple – you should be able to construct them reading the book and looking through the material for Chapters 1-‐4. One pattern we see when beginning students are trying to write a simple program is that they get part way done and get stuck on a little problem – like a bad indentation error or something – when you can’t fix the problem right away (often the error messages are a bit cryptic) – you conclude that everything you know is wrong and throw the whole program away and try to rewrite it from some other approach. Often this second approach is less “correct” than the first approach – and has lower chance of success than the first approach. So after an hour of pain, the second try fails and you make a fresh third try – which is an even weirder approach – resulting in another hour of pain. By this point – you completely have lost what you learned – and often the 8-‐line program with one small error has become a 40-‐50 line monster with lots of bits of code typed in randomly from the slides, books, and Google. You look at the monster code and decide that programming is impossible. (Actually it is impossible to just paste in random bits and get it to work). So the right reaction when you kind of have your program looking like you think it should look – but there is one silly error – get help. If you get help and quickly get past the little error – you will realize that you actually knew 95% of the program – and yeah there is some little trick about mixing tabs and spaces and you just won’t do that again. It takes a few minutes to get some help mailing your GSI or mailing the whole class list in a pinch. Don’t just get mad and try to put random things in your code to make it work. Sample Screen Shots Here is a sample screen shot of running Python interactively (similar to Exercise 1.3) Here is a sample screen shot of running exercise 2.3 (not assigned):
© Copyright 2026 Paperzz