# Using PyCharm and submitting assignments This course will have weekly assignments. Lab time each week will be used to complete the first part of each assignment and to ensure that you have all the tools and skills to successfully complete the assignment. Most assignments have a second part, which you may finish and submit later. For most assignments, you will be required to do a little pre-lab study and answer a few planning questions before the start of the lab. In general, for lab time to be as effective as possible you should review your lecture notes, the reading and the assignment before coming to lab. You might want to have the online copy of the textbook, and/or the documentation available through [python.org](http://python.org), on your screen while you work through the lab exercises. The purpose of this first lab is to ensure that you: 1. can log in to the lab machines. 2. have a working PyCharm development environment (optionally on your own personal machine). 3. can create a PyCharm project and download/import sample/starter code into it. 4. can create and execute simple Python programs 5. can properly use the automated submission system. | Part | Section | |---------------|-----------------------------------------------| | 1 (in-lab) | [Description](#part1) | | 1 (in-lab) | [Check-in Instructions](#checkin) | | 2 (lab/home) | [Description](#part2) | | 2 (lab/home) | [Submission Instructions](#submission) | <a name="part1"></a> ## Part 1: Bring up PyCharm and create a simple project In this class we'll work within the PyCharm integrated development environment, so this part gets you started with using the interpreter through PyCharm. In Part 1 of this lab you will: - log into a lab machine - (optional) install Python 3.7 and PyCharm on your personal machine - create a PyCharm workspace and start PyCharm - create a new Python project and download/import a starter - edit and run this program The focus of Part 1 is to get you familiar with PyCharm, the IDE that we'll be using for the rest of the semester. You should feel free to ask each other for help, to check your answers with each other, and so on. In fact, for today, you should make sure to ask for help if at any point the instructions about PyCharm setup seem confusing. We really want everyone's workspace to be set up the same way so that instructions for subsequent assignments make sense! Finally, while you're encouraged to talk to one another, you need to make sure that you fully understand the material. Before you can receive the points for Part 1, you'll need to find an instructor or a TA. We'll look over your work and ask you some questions about the content. Then we'll give you points. ### 1.1 Logging in You should be able to log into any lab machine using your Pomona account. It does not matter which lab machine you log in to. Any lab machine should recognize your account and take you to the same Desktop. The first time you log in the system may be very slow, as it creates a new Desktop for you (and because many other students may be doing this at the same time). If you attempt to login to a lab machine before the lab, you can (a) get this over with and (b) deal with any problems before the actual start of the lab. If you are unable to log in to a lab machine with your Pomona account Username and Password, you need to contact the ITS for help. Python and PyCharm are already installed on the lab machines. If you choose to use the lab machines, then you can skip the next section and start to work on the lab. However, we highly recommend you to install Python and PyCharm on your personal laptop, as it is more convenient and easy for you to access your work. ### 1.2 installing Python and PyCharm You are welcome to do these projects entirely on lab machines, entirely on your own machine, or some combination (e.g. part 1 on lab machines and part 2 on your own personal machine). If you want to use your own personal machine, you will need to download and install Python and PyCharm. The latest Python interpreter can be downloaded from [www.python.org/downloads] (https://www.python.org/downloads) (with packages for [Windows](https://www.python.org/downloads/windows/) and [Mac OS X](https://www.python.org/downloads/mac-osx/)). You should select the latest distribution of Python 3.10.6, and install it after it is down-loaded. PyCharm can be downloaded by going to [JetBrains](https://www.jetbrains.com/pycharm/download/). ***Make sure you download the (free, open-source) Community Edition***. ### 1.3 Starting PyCharm Launching on the lab machines: Find the globe icon in the bottom right of the launcher bar, click it to open a Finder window on your network drive (also known as your home directory). <img src="figures/ss0_launcher.png" width="500" height="300"> In the left pane of the Finder window, click `Applications`, and then scroll down to find "Pycharm CE". <img src="figures/ss2_applications.png" width="500" height="300"> Double click the `Pycharm CE` icon to start Pycharm. A dialog box may say "Pycharm CE is an app downloaded from the Internet. Are you sure you want to open it?" Click `Open`. The next dialog box will say "JETBRAINS COMMUNITY EDITION TERMS". Click the checkbox to accept the User Agreement, then click `Continue`. The next dialog box will say "DATA SHARING". Click `Don't Send`. You should now be in Pycharm, which looks like this. <img src="figures/ss3_welcome.png" width="500" height="300"> Launching PyCharm on your personal laptop: - On a Mac you can start PyCharm by clicking the `PC` icon on your menu-bar. - On an Ubuntu system you can use the Application launcher search function to find it, and then add it to your menu-bar. - On a Windows system you can click `Start` and search the name of `PyCharm` to find it, and you can drag it to generate a shortcut or pin it to the start menu. ### 1.4 Creating a new project PyCharm will, by default, try to maintain all of your projects under a single folder. Before starting PyCharm for the first time you should create a new workspace folder. *On lab machines:* Click the globe icon at the bottom of the launcher bar to open a Finder window on your network drive (also known as your home directory). Right click inside the network drive and choose "New Folder." Name the new folder "CSCI051p-Workspace". <img src="figures/ss1_newfolder.png" width="500" height="300"> Now, you can go to PyCharm window, and click the `New Project` button. - The `Location` field will be pre-filled to something like `/Users/xxx99999/CSCI051p-Workspace/pythonProject` where `xxx99999` is your username. Delete this field. Replace it with `/Volumes/xxx99999/CSCI051p-Workspace/Setup` where you have again replaced `xxx99999` with your username. Example: for the username `tyc04747`, the correct path is `/Volumes/tyc04747/CSCI051p-Workspace/lab01` - Make sure "New environment using Virtualenv" is selected. - Uncheck the box labeled "Create a main.py welcome script". Except for the place where your username appears and the project name (it should be Setup, instead of lab01), the project configuration should look like this: <img src="figures/ss4_project.png" width="500" height="300"> Click `Create.` A dialog box will say "Pycharm CE would like to access files on a network volume." Click `OK`. When the project is created, dismiss the "Tip of the Day" by clicking Close. A notification box in the lower right of the Pycharm window will say "External file changes sync may be slow." Dismiss it by clicking the X. When you are finished, you should be in a Pycharm window that looks like this: <img src="figures/ss5_finished.png" width="500" height="300"> *On personal laptop:* We suggest that you create a new folder on your desktop named `CSCI051p-Workspace`. After starting PyCharm you can accept the defaults and, eventually, should get to a screen that invites you to select ***Create New Project***. Go ahead and create the project, making sure that the location of the project is a new sub-folder (e.g. `Setup`) in the `CSCI051p-Workspace` you just created on your Desktop. In the configuration window, you need to click on the folder button as shown below to navigate to your Desktop, and then select the `CSCI051p-Workspace` to open. After that, in the Location bar, you need to manually type in the subfolder name `/Setup` to create this new subfolder. You configuration window should like similar to this: <img src="figures/env.png" width="500" height="300"> ***WARNINGS for new project creation*** - make sure you put the new project in the Workspace folder you just created. Not in the default location, which will be very difficult for you to find. - check the option `New environment` using Virtualenv to create a virtualenvironment, as highlighted in the above picture. - make sure the python base interpreter is `python3` - uncheck the option `Create a main.py welcome script`, as highlighted in the above picture. ### 1.5 Editing and running a Python program Download the [setup.py](setup.py) starter file for this assignment, and copy it into the (recently created) `CSCI051p-Workspace/Setup` folder. Then ask PyCharm to re-scan that folder by clicking the triangle next to that folder (on the left-side list) to close and re-open it. The newly added `setup.py` should now be visible. If you double-click it (in the left-side list), that file should appear in the main editing window. You should now be looking at the main screen: - a menu bar at the top - a (nearly empty at this point) list of projects and files on the left - a main window - a list of screen selections on the bottom <img src="figures/pycharm.png" width="500" height="300"> The easiest way to Run a program that you are editing is to place the cursor in the file editing window and right-click. One of the options will be `Run` (and the name of the currently selected file). If you select this option, the Python interpreter will execute the selected program and display the output (in a `Run` window) at the bottom of the screen. If you have run multiple programs, you can choose which one you want to run with a selector and buttons near the top right of the screen: - a drop-down list contains the names of each previously run file. - a triangular run button will re-run the selected program. You can also select `Run->Run` from the top menu-bar and then choose (from the supplied list of previously run programs) which one you want to run. #### 1.5.1 Changing the `print` statement Edit the supplied starter and change the `print` statement to print out the class, your name, and the assignment number. Sample output might look like ``` CS051P Riley Greatstudent, Assignment #0: Setup ``` Run the program and confirm that it now prints out the correct information. <a name="checkin"></a> #### Checking In If you are doing this assignment in the lab, call over an instructor or TA to check your output and code. If you have successfully gotten PyCharm started and made and run the above changes, they will award your points for Part 1. If you are not doing this assignment in the lab, take a screen-shot of the PyCharm window that shows your edited program and the output from running it, and e-mail it to your Instructor. <a name="part2"></a> ## Part 2: Commenting, Feedback and Submission ### 2.1 Commenting your code Code is written both for the machine and for people (both for other people such as TAs and for future-you). As a result, it is critical that you comment your code both for this class and for anything else you write. The following are two ways to comment code in Python; you should become comfortable with both. - Any text that comes after a `#` and before a newline is ignored by the interpreter. This can be used to introduce a short single-line comment. - Multi-line (or block) comments are enclosed in triple quotes. Examples of both can be seen at the beginning of the supplied starter. Change the block comment at the beginning of the file to have your name. After you have made these changes, run the program again to make sure you have not made any mistakes. A fuller discussion of commenting and code style can be found in the [Python Coding Style Guidelines](../../python_style.html). ### 2.2 Feedback Create a file named `feedback.txt` (in the same folder) that answers the usual questions: 1. How long did you spend on this assignment? 2. Any comments or feedback? Things you found interesting? Things you found challenging? Things you found boring? <a name="submission"></a> ## Submission For this lab you are required to submit two files: - `setup.py` your updated and commented version of the supplied starter file. - `feedback.txt` a text file containing your feedback for this assignment. These should be submitted using [Gradescope](https://www.gradescope.com). Note that you will lose credit if your submitted files are incorrectly named. ## Note on Academic Honesty You are encouraged to demonstrate your working code to each other. You are even encouraged to be inspired by what other people have done in order to make your own program even more amazing. However, if you do so, you *must* acknowledge them (both name and what exact idea you used from them) in that multi-line comment at the top of your program. Note that you also must acknowledge any other sources that you are inspired by (e.g. a submission based on HAL 9000 from Arthur C. Clarke's novel `2001: A Space Odyssey`). From experience, we know that dealing with academic honesty cases is extremely stressful for everyone involved. Please don't let it come to that. ## Grade Point Allocations | Part | Feature | Value | |-----------|-------------------------------------------|-----| | Lab | Importing starter into PyCharm project | 5 | | | | | | Execution | prints course, name and assignment | 5 | | Execution | no errors | 5 | | | | | | Style | Correctly named file | 2 | | Style | file-level block comment | 2 | | | | | | Feedback | Completed feedback file submitted | 1 |