Difference between revisions of "CSC111 Lab 1 2011"
(→FUN WITH PYTHON) |
|||
Line 3: | Line 3: | ||
__TOC__ | __TOC__ | ||
<center> | <center> | ||
− | [Image:PythonLogo.jpg|200px|right]] | + | [[Image:PythonLogo.jpg|200px|right]] |
=FUN WITH PYTHON= | =FUN WITH PYTHON= | ||
</center> | </center> |
Revision as of 12:37, 6 September 2011
--D. Thiebaut 12:12, 6 September 2011 (EDT)
Contents
FUN WITH PYTHON
This lab is just an introduction to having fun with Python. It's purpose is to have you explore the different systems that are available to you, and get a sense of how to program in an "intuitive" fashion.
Python on the MAC
- If your computer is not on, turn it ON!
- When prompted for booting Mac or Windows, select the Mac
- When prompted for an account and password, use the 111a-xx account that will be given to you in the lab.
- Once you see the Desktop, click on the Finder (bottom left icon on the Desktop), and look in the Science Apps folder for Python 3.2.
- Start IDLE
Tip: if you can't find Idle, use the magnifying glass icon at the top right of the screen and search for idle and you should find it!
Idle
- If the window you start with looks like this (see below), then use the top menu and click File, New Window to open an editing window.
- You should now have two windows on your screen, one the editing window, the other the shell window, where the program will send its output.
Some Python Code to play with
Playing with numbers
- Enter the following code in the Untitled window:
a = 3 b = 5 c = 10 print( a, b, c, a+b+c )
- Press F5 to run the program. When prompted to save the program, save it as lab1.py
- Verify that you get something that makes sense.
- change the values that are assigned to a, b, or c and see how your program reacts when you run it.
Using Strings of characters
- Modify the print statement so that it reads like this:
print (a, b, c, "sum = ", a+b+c )
- Run your new program. Does the output make sense? Don't worry too much for today if it doesn't. Be sure to ask questions to your instructor or to the TAs if you're unsure about anything.
- Another modification. Replace your print statement by two statements:
print( a, b, c ) print( "sum = ", a+b+c )
- Run your program. How did the second print statement modify the behavior of your program?
Challenge #1
- Now, use your intuition and what you have just learned and see if you can modify your program to make it display this output:
a = 3 b = 10 c = 20 sum = 33
- Keep at it if you don't get there right away. Remember, this is a language, and you have many different ways to say the same thing...
Useful Links
- If you want to install Python 3 on your Mac or Windows laptop/desktop, check out this page and follow the links for the appropriate operating system.