CSCI 102 - Intro to Computer Science LABWeek 00Quick Links: zyBook | Piazza | Canvas | CS @ Mines |
|
| Home | Contact | Schedule | Assignments | Syllabus | | |
Week 00: Hello World!
NOTE: skip to Step 2 if you are using Python on
a lab machine (i.e., NOT installing Python on a laptop).
Step 0: Download Python Programming languages are how we communicate with our computers. To ensure that your computer speaks Python (and therefore understands the instructions you'll be giving it), you'll need to download a Python interpreter. The interpreter we'll be using is for Python 3 (a slightly different dialect from Python 2). Head over to python.org and find the download button for the latest Python 3 version for your computer's operating system. Click it! The button circled in green is probably the one you want (verify that the number starts with a 3, and that the OS I've circled in red matches your computer's OS). Step 1: Run The
Installer
Once the installer downloads, go ahead and open it and follow the installation steps. Let the instructor or ugrad TA in your section know if you have questions. Step 2: Try Out IDLE
One of the things your installer should have given you is a program called IDLE. One of the most useful things to do in a program is to get output. In Python 3, we do this using the print() function: print() is a function which takes input (e.g., "Hello, world!" in our example), does things (in this case, prints the input to the console), and returns things. The input to a function is called its argument(s), which go in the parentheses of a function call. The argument to the print() function is the string "Hello, world!". Notice that a string is like a quote in a paper – it starts and ends with quotation marks, and what gets printed is exactly what you type between those quotes. Why call it a "string"? It's a bunch of letters, strung together in a particular order. To run code in IDLE, you can just type it in after the >>> prompt. But you have to type every command in every time. It can be very useful to save your commands in a separate file, called a script or sometimes even a program. In IDLE, select File > New File (click the "File" menu and find the "New File" option). In this new window, type print("Hello, world!") and then save the file as helloworld.py. Then, with your script file selected, select Run > Run Module. This will take you back to the first IDLE window and show you the output of your program. |
|