CS 115 Lab 1, Part B: Writing a Python program using PyCharm

[Back to Lab 1]


Summary

In this part of the lab, you will use PyCharm (http://www.jetbrains.com/pycharm/) to write and run a Python program. The screenshots on this page were taken on a Mac. For now, that is the operating system that you should run in our labs.

Instructions

  1. Find the PyCharm icon on the menu-bar, as displayed below, and double-click on it to launch PyCharm.
    Double-clicking PyCharm Icon
  2. The following screen will pop up. The first time around, it may take a bit longer for it to launch.

    PyCharm Welcome Screen

  3. Select Create New Project. A new window will appear as shown below.

    PyCharm Create New Project

  4. You create a new project for every lab for this course. So, let's call the project for this lab, Lab01. Click Create button on bottom right of this window.

    PyCharm Create New Project

  5. When you create a project, PyCharm creates a folder (directory) for you so that you can store all files that are related to that project in that folder. Double-click on Lab01 (top-left) to see the following image.

    PyCharm Create New Project

  6. Right-click the mouse in the highlighted project-name and then slide the mouse and place it on New menu-item and then file.

    PyCharm Create a new file

  7. Now, type the name of the Python program for this lab, lab01.py and click on OK

    PyCharm enter the new file-name

  8. Now, PyCharm is ready for you to enter code in the file that you just created.

    PyCharm file ready for contents

  9. Copy and paste the following code-segment into the empty panel.

    """
    
    Lab 1: This program prompts for your name and then greets you by name.
    Author: ____________
    """
    
    
    def main():
        name = input('What is your name? ')
        print('Hi there, ', name)
    
    
    main()
    
    
    PyCharm code entered

  10. Modify the docstring at the top of the program to add yourself as the author of the program.
  11. Go to the Run menu (on the top of the screen), then select Run. A sub-window opens up:

    PyCharm run the program

  12. Click on lab01 to run the program.

    PyCharm run the program

  13. Notice that the code-window splits and in the bottom window, the prompt appears. Put the mouse in the bottom window and type your name at the prompt and hit the return key.

    PyCharm run the program

  14. To run it again, click on the green arrow on the top-right corner of the code-window.
The program that you just created is stored in cs115user/PycharmProjects/Lab01/lab01.py as depicted below.

PyCharm path to the program

Please note that if you were to restart your machine, the Lab01 folder and lab01.py will be deleted. So, you have a few option to preserve your work.
  1. Save it on a flash-drive. You are welcome to bring a flash-drive with you and, when you are prompted to type-in the name of a project you can choose your flash-drive and create/copy the project folder on it.
  2. Or save it on the CS Department's Linux server. It is called blue. In a future lab, you will learn how to store your files on blue but for this lab you may consult your lab instructor to get help.

Continue to Part C.