**Project 0: Set-up and Submit!** **Reed CSCI 121 Spring 2025**   *complete this before the first lab* Here we set-up the software necessary for completing and submitting your work throughout the semester, and we try out some Python programming. By the end of this homework you'll have run the Python interpreter, written some Python code, tested that code, and submitted it to us so that we can take a look at it. In doing so, you will interact through Gradescope and our automated system that works to check your work and tries its best to give you feedback on it. --- # Set Up Before we get into the substantive material of the course, we need to make sure your computer has all the software necessary for the course and show you how to use it. This assignment walks you through that process. We have tried to include detailed instructions, but if anything isn't working, you can get help from us to complete the work. In order to do the work of this class, you'll need the following: * **Gradescope:** This is the site where we'll submit assignments for this class. * **Python 3:** This is the interpreter that runs code written in the Python 3 programming language, which we'll be learning. * **Terminal:** This is a text-based interface where you issue commands to the computer. You can do lots of things with it, but we'll be using it to run Python files. * **Text editor:** This is a program for editing files that consist of text (including, for example, Python files). In particular, we'll want a powerful editor meant for use by programmers. Below are instructions for installing each of these things. The instructions are meant to work for Windows, Mac, or Linux computers, so they ought to be relevant to your computer. There are also several “exercises” you have to complete. These are very basic and really just meant to test that you have everything set up correctly. ## Join Gradescope Your first step is to create a [Gradescope](https://www.gradescope.com) account associated with your Reed email. In doing so you can join the [CSCI 121 Spring 2025 course](https://www.gradescope.com/courses/967569) on Gradescope by using the course code we'll provide in this lab. You need to join Gradescope in order to submit the work of this assignment and all the future assignments. If you officially registered for this course before this past weekend, you should have received an invitation from Gradescope to join the course. Just follow the links and instructions in that e-mail. It should be pretty straightforward to join. ## Text Editor You're going to need a text editor to write code for this class. You do not want to use Notepad, TextEdit, or other minimal default text editors that come on your computer. Fortunately, there is a wide variety of (mostly free) excellent text editors out there. These powerful editors are made with programmers in mind, and they have a variety of features that you will find useful. Many good text editors are available, and many of them are free. You should choose one and download it. We've listed some good options below (along with some caveats about them), but you're welcome to use others if you prefer. (We recommend, however, that you use a simple text editor, rather than a complex integrated development environment (IDE), at least at first.) * [**Notepad++**](http://notepad-plus-plus.org/) Only available for Windows. * [**CotEditor**](https://coteditor.com/) Only available for the Mac. You will need to set two simple preferences for the font and for tabbing. * [**Visual Studio Code**](https://code.visualstudio.com/) Available for the Mac and for Windows. * [**Atom**](https://atom.io/) Works on all systems. No longer officially supported or developed, but you should still be able to download it and use it just fine. You'll need to make a github account to use it. * [**Sublime Text**](http://www.sublimetext.com/) Works on all systems. You will need to set up a tabbing preference. This is “freemium” software. There's a paid version and a free version. With the free version you'll get occasional pop-ups asking you to upgrade, but you can continue to use the free version and ignore those. * [**BBEdit**](https://www.barebones.com/products/bbedit/) Only available for Mac. There is a free and a paid version, but the features missing from the paid version shouldn't matter for anything you're doing in this course. We'll do most of our coding in an editor, and coding is best practiced with a fixed-width font. This means that every letter, symbol, and space in your document will occupy the same width and height, and so your text will be lined up in same-width rows and columns: ~~~none Here is text in a fixed-width font. The text is lined up and laid out in a grid, because each symbol occupies the same area. ~~~ To get this, the text editor you choose may need some configuration in its preferences: * **Font:** You'll want the default editing font to be a "typewriter font" or "computer terminal font," something like Courier, Monaco, or Menlo. * **Tabbing:** When we program in Python, we use spacing at the beginning of lines to indicate on each line what the program should do next. We will hit the TAB key to indent lines in multiples of 4 spaces. Some editors will need to be configured to do this. Make sure your editor's tabbing default preferences are set to treat a tab as 4 spaces. ## Exercise: complete a survey Next we're going to edit a text file. Make a folder on your computer where you will store your work for this class. You'll probably want folders within that for each lab homework and project. It's best for our purposes to not include spaces in the names of those folders. A folder named `cs1` or `csci121` with a folder inside named `project0` or `pj0` might be best. You can put these inside `Documents` or `Desktop`, whichever you most prefer for yor work. Now [download the `survey.txt` file](project0/survey.txt) and open it with your editor. Fill in answers to the questions, and then save the file. (We'll submit this and the work of another exercise in the last step of this assignment.) ## Terminal and Python We will run our programs using terminal commands. The terminal is a text-based interface where you can issue commands to your computer. It's a very powerful tool, and programmers use it all the time. You'll only get a very basic introduction to the terminal in this course, but it's still very important to what you're doing. In particular, what we're going to be doing with the terminal is running Python programs, and for that we'll need to download the Python interpreter, the program that carries out the instructions we'll write in Python. (This program is not something you can open in a window-- you call it from the terminal or some other program.) Depending on your operating system, you might have some of this installed already. Follow the instructions below for your operating system. **Mac** Macs come with a built-in terminal, which you can easily find by using the Spotlight search feature. Macs also come with Python installed, but unfortunately it's Python 2, which is not what we're using. (Be careful-- you can get through a little bit of the class not realizing you're using Python 2 by accident, and then eventually things stop working right.) You should go to the Python website and [download and install the latest version of Python 3](https://www.python.org/downloads/) (currently 3.13.1). To check that it works, open up the terminal and type `python3` (and hit enter). You should see something like the following: ~~~ none Python 3.12.6 (v3.12.6:a4a2d2b0d85, Sep 6 2024, 16:08:03) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> ~~~ Crucially, the version number at the top indicates that it is Python 3, not the Python 2 installation that comes with your computer. (You should leave the Python 2 installation alone-- your computer relies on it for various things.) Type `quit()` to get back to the regular terminal prompt. **Linux** Linux also comes with a built-in terminal. It also often comes with a Python 3 installation. You can type `python3` or `python` at the command line to see if one is already there. (If it is, you'll see something like the terminal response shown above in the Mac section.) If it is not, go to the Python website and follow the installation instructions. If it's there, and the version is 3.X.Y, for some value of X that's 10 or greater, then you're fine. If you want to take the time to upgrade to a newer version, that's great, but it shouldn't be necessary. Type `quit()` to get back to the regular terminal prompt. **Windows** Things are a little trickier on Windows, just because we're trying to maintain consistency in the class. You have two options for what to do. One thing you can do is use the "command prompt" as your terminal-- this is the Windows equivalent of "terminal," and there's nothing wrong with it at all. But it's different than terminal, so some of the instructions we give for how to use the terminal will be slightly different if you're using the command prompt instead. We're not doing anything extreme in this class, so the differences will be quite minor, but you might need to look things up a little bit. If you want to do this, then you need to download Python 3 from the Python website, just like the instructions for Mac users above. The only difference is that installations in Windows usually default to using the `py` command instead of `python3`, so make sure you try that at the command line when you're looking for the successful Python installation. The other option on Windows is to install the **Windows Subsystem for Linux**, which is essentially a small Linux environment that you can run on Windows. This lets you use a fully Linux-style terminal, just like you would see on a Linux or Mac computer. You do this by going to the Microsoft store, finding the Ubuntu application, and installing it. (Ubuntu is a popular Linux distribution.) When you run it, you should see a terminal window pop up. The first thing it will do is prompt you to pick a username and password-- do that. Then try typing the `python3` command-- you should find that there's a Python installation already there. Then follow the Mac and Linux instructions above that discuss checking the version. ## An Interactive Python Session Python is a programming language. You can write large files full of many lines of code and have Python run the whole file. But you can also use Python in an interactive mode, where you can write single lines of Python, and the Python interpreter will evaluate them each one-by-one as you type them. Go to your terminal and type the command for Python there. (This is usually `python3`, but it could be `py` or `python` or something else, depending on how it was installed. You can also create an alternate command if you feel ambitious and want to look up details of how the terminal works.) When you do this, you should see the version information discussed above in the installation instructions. The key thing that you should see is the *Python* prompt `>>>`. Here you can type individual lines of Python code and watch them be evaluated immediately. If you type `4+5` and then press the `[return]` key, it should print `9` on the next line and give you a new `>>>` prompt. Try each of the Python code suggested below and make sure that you get the same responses. The lines starting with `>>>` contain the code you should type at the prompt. The other lines should appear automatically as responses. ~~~ python >>> 18 % 4 2 >>> x = 7 >>> print(x) 7 >>> from math import pi >>> pi 3.141592653589793 >>> quit() ~~~ The last line with `quit()` tells Python to exit and should return you back to the terminal so that you can enter console commands, not Python expressions. ## Exercise: run a test program Next we want to run a Python program from the terminal. [Download the file test.py](project0/test.py) and put it in your project folder. To run it we'll need some simple terminal commands-- in particular we need `cd` and `ls`. (Note the extra instructions for Windows users below.) When you're working in the terminal, your computer keeps track of the directory/folder you are currently working in, even if it's not displayed. (If you're unsure, you can type `pwd` for "print working directory" and it will tell you where you are.) You should start by default in your computer's home directory. If you ever want to return directly to the home directory, you can type the `cd` command (for "change directory"). You can display the contents of the directory you're in (both sub-directories and files) by typing the `ls` command. If the folder you're in contains the sub-directory named "lower", you get to it by typing the command ~~~none cd lower ~~~ If you want to move up one level into the parent folder of your current directory, you do it with the command ~~~none cd .. ~~~ A series of `cd` commands should let you navigate to any folder on your computer. You should use these commands to navigate to the folder where you're storing your Project 0 work, and you should make sure it contains the `test.py` file that you just downloaded. Then run the command `python3 test.py` at the terminal. (As always, I use `python3` because that is the most common default command for Python 3, but it could be different on your computer.) When you put a file name after the Python command, you don’t get an interactive session like we did above — instead the interpreter carries out the contents of the file. In this case, that should result in a number being printed to the terminal. Find this assignment on Gradescope and enter that number. **Windows users using command prompt** You will need to sometimes look up command prompt commands, but here the only difference should be that you use `dir` instead of `ls` to display the contents of a directory. **Windows users using WSL Ubuntu** You're using a real Linux prompt, so the commands are the same as those discussed above. The only tricky thing is that the file system is organized a little bit weirdly. The Linux installation has its own home directory, and your computer's regular file system is listed as if it's an external drive. To find it, navigate up to the root directory. You should see a directory there called `mnt`. Navigate into that, and you should see that it contains all your computer’s regular drives (including the `C` drive, which is probably where your homework folder is.) So for example, if you normally have a folder for Python code at the top level of your computer, `C:\python`, then in the Linux installation you would find it at `/mnt/c/python`. (Another Windows/Linux difference is that the slashes in file locations go the other way-- backslashes on Windows and slashes on Linux.) ## Exercise write a Python program Now we want to practice writing an actual Python program, meaning writing Python code in its own file. You should start your editor and open a new file. In some editors, it might ask you what kind of file, or in what programming language, you will be writing. If so, find the option that allows you to create a new Python source code file. Now go ahead and type the following Python code into the file (perhaps replacing any initial text that the editor automatically provided). The file should just be this code: ~~~ python def first(a, b): c = 3 if a > b: c = 4 return a**c - b ~~~ You will want to literally type in the code, rather than cut and paste. Some characters that appear in documents look the same but are not the same as the keys you would press yourself (double quotes and hyphens are notorious examples of this trickiness). Furthermore, you should make sure that you indent each of the lines after the first using spaces-- 4 spaces for lines 2, 3, and 5; 8 spaces for line 4. (If your editor is configured correctly to treat tabs as spaces, you can tab once for lines 2, 3, and 5; hit tab twice for line 4.) Save the file with the above code as `first.py`. Most text editors will now know that your file is a file of Python code and will color it accordingly, with specific colors assigned to functions, variables, etc. ## Run your first program Now I know that you probably followed our instructions well and copied the code verbatim. Even so, you should want to see if the code works before you hand it in. We will explain this more carefully in future lectures and labs, but there is no harm in just trying things out now. In the terminal type the following command: ~~~ none python3 -i first.py ~~~ This is the same `python3` command you entered earlier along with some extra information. This runs the program you've written in a different way. It reads in the code in `first.py` code first, and then allows you to *interact* with Python, prompting you for more Python code. For example, here is a session that I ran with my code in the terminal: ~~~ none >>> first(100,1) 99999999 >>> quit() ~~~ Here, havingh run Python 3 within a terminal, I enter a Python expression after the `>>>` prompt. Python responds on the next line with a number computed from the expression `first(100,1)` If instead you see errors rather than an integer, email us. To stop playing with the code within Python, Enter `quit()` at a `>>>` prompt to leave the Python system and go back to entering terminal commands. Understand that this is hardly testing the code, and rather just an easy sanity check compared to what we expect for later homework and projects. ## Submit your work We're ready for the final step, submitting the completed work. To do this, go to Gradescope (and log in) and navigate to the site's [CSCI 121 Spring 2025 course](https://www.gradescope.com/courses/967569) page. You should see several assignments there, including ones labelled **[Pj0 Ex1]**, **[Pj0 Ex2]**, and **[Pj0 Ex3]**. When you click on the first and the last of these, you'll get a *Submit Programming Assignment* pop-up that will ask you to upload the file you need to submit for that problem. For "submit your survey," upload the file `survey.txt`, but only once you've edited and saved it with your survey responses. For "submit your first," upload the file `first.py`, but only once you've run it yourself. For each, the system should tell you that the problem was successfully submitted. The system inspects the files you submit and does work to give you more detailed feedback on their contents. In the case of the first problem, your submitted survey will get scanned by a script. In the case of the second problem, the code you submit will be run by a test script. For each, some results should appear shortly and a score will get reported. Sometimes the system is slow but the score should eventually appear. Let us know if for some reason it does not. For the "report `test.py` output" exercse, you'll need to fill in the number printed by your run of that `test.py` script. This is just a sanity check that you ran the correct version of Python, version 3. If not, we can work to correct the installation on your computer. If you see an autograder score above 0.0 for each, you will have completed this assignment. Congrats! You're ready to do more interesting things in the first Tuesday lab meeting. # Appendices ## Appendix: configuring Atom tabbing You can configure **Atom** to use spaces by going to the menu bar at the top of the screen and finding the menu selection *Atom > Preferences...*. This will bring up a *Settings* pane with an option list *Core*, *Editor*, etc. Select *Editor* and scroll through the various configurable options scanning for a check-box named *Soft Tabs*. Select this option with a check mark so that "soft tabs" are enabled. "Soft" means that when you hit the `[tab]` key a number of spaces will be entered instead. ("Hard" would mean that an actual tab is inserted.) You should also change the *Tab Length* setting (just a little below the soft tabs setting). Set its field to `4`. **Atom** can be clever in reading source code that was written using different settings. It is willing to work with both hard tabs and soft tabs, mimicking the file it is reading. If you set the option *Tab Type* to `soft`, then it will just always insert spaces when you hit `[tab]` regardless of the other sections of the code. This is probably the option you should prefer. ## Appendix: getting a Windows terminal using Git tools A different option for getting a terminal on Windows that has worked for CSCI 121 students in the past is to download and install a program provided by the GitHub service, as part of its Windows tools, called [GitBash](https://gitforwindows.org/). If you can get this installed, it works the same as the terminal programs on the Mac and on Linux. ## Appendix: getting a Windows terminal using WSL A fairly advanced option for getting a terminal on Windows is one used by students taking our CSCI 221 course. You can install a **Windows System for Linux** or **WSL** on Windows. A WSL is a bit more feature-rich than Powershell and GitBash (described just above). It essentially has you put a mini Unix computer system (sometimes called a "virtual machine") onto your computer. This will be especially useful after this course, as you'll probably see need to use other Unix tools beyond those for Python programming, and the skills you've learned in this class will probably motivate you to do so. To install a WSL open up the **Microsoft Store** and search for **Linux**. This will bring up several Linux distributions as applications that you can download. Select the **Ubuntu** one and install it. Alternatively, you can probably just search directly for "Ubuntu" in the store. Once you've downloaded that software application, go ahead and run it. Running the Ubuntu WSL brings up a Unix console window, one that will (because it is your first time running it) ask you to name your WSL user and provide its password. I recommend using your Reed login name and password here, but you can choose whatever you like. This username/password combo will be what you type in every time you run this Ubuntu WSL application. Because this acts like a computer within your computer, it acts like it has its own structure of files and folders. But you can access your normal Windows system files and folders (the stuff that's normally on your `C:` drive) using a special "folder path" here within WSL. For example if you type the command ~~~ none cd /mnt/c/Users/WINDOWS-NAME/csci121 ~~~ where `WINDOWS-NAME` is your Windows user name, this will take you into the folder we had you make with the "**Make coursework folders**" step up above. If you don't know your Windows user name, typing the command ~~~ none ls /mnt/c/Users ~~~ should give you a list of possible user names on the system, and it should hopefully be obvious which one is yours. It's also possible to create a shortcut to your coursework folder within this WSL subsystem. If you enter the commands ~~~ none cd ~ ln -s /mnt/c/Users/WINDOWS-NAME/csci121 csci121 ~~~ then this will create a "symbolic link" called `csci121` in your WSL user's home, and that is a system item that refers to the actual `csci121` folder in your Window's user's home. This all sounds complicated, and it's not necessary for this course. Nevertheless, some of you might enjoy giving it a try.