Academic Resource Center

Python, PyCharm, & Zybooks Complete Guide

Updated on

Python is a very popular programming language used for creating a wide variety of software for various purposes, such as task automation, creating web sites, running servers, and many more. In order to interact with Python, the simplest, and most traditional, way to use Python is via the command line and providing a valid Python file for it to run.

Besides that very direct method, other ways we can interact with Python is using an IDE (Integrated Development Environment) like PyCharm, and through other third-party tools, such as zyBooks which is designed to help teach us Python!

However, because there are so many ways to work with Python, along with various other nuances that come up when using zyBooks, especially for students that have likely never worked with programming before, it can be difficult to get started.

To help with this issue, the rest of this document will describe the basics of Python, how to work with PyCharm, and will also provide a deeper understanding of how to work with labs in zyBooks.

Introduction to PyCharm

The first step will be to download the PyCharm software from their website onto our computers, so we can install it and use it. The PyCharm Community Edition can be downloaded at:

*Note: Make sure to download the “Community” edition, NOT the “Professional” edition, which only contains a free trial, and when that trial ends, we’ll no longer be able to use PyCharm without purchasing a license. The Community edition will always remain free and will contain all the features we need for learning Python.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Creating a new Project

Once the PyCharm installation is complete, the program may open automatically. If it does not, find the PyCharm program on your computer and run it. Once PyCharm starts up, we should be met with the following “Welcome” screen:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Let’s select the “New Project” button, which will bring us to the “Project Creation” screen

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

There’s a bit of information on this screen, but there are only two sections we need to consider and take note of:

  • Location – This is where this particular Python project (that we’re about to create) will be found on your computer. When you need to copy the python files we create in our project, for uploading to Brightspace, or for using these files for other purposes, we’ll be able to retrieve them by navigating to this location on our computer.
    • NOTE: We’ll be making use of this location later, so be sure to make a note of it before continuing
  • Create a main.py welcome script – When we check this box, PyCharm will automatically create a python file for us called “main.py”, with some placeholder python code, which we will see in the next few steps

Once the location is noted for later use, hit the “Create” button.

Layout of PyCharm

If it’s the first time that you’re working with Python on your computer, it may take a few minutes or longer to do a one-time initial set up Python before we can start interacting with PyCharm. Going forward, when we make future PyCharm projects, we won’t have to do this initial setup, and the process will be much quicker.

Once the PyCharm project is finished creating, we should see a screen like this:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

The layout of PyCharm is as follows:

  • The 3-horizontal lines at the very top-left (circled in red) is the main menu for PyCharm, which we’ll make use in a later step.
  • Beneath that is the project directory for our current PyCharm project (circled in green), which contains all the files for our Python project.
  • On the right, in the main portion of the screen, is where we can edit code in the current file we’re viewing. Right now, we’re viewing the default main.py file.
  • In the top-right part of the screen (circled in blue), there is a green “play” button. This is how we can run our Python code. When we hit that button, our code will run and be displayed in the output window on the bottom of the screen (also circled in blue)
    • This bottom output screen may not be showing until our code is run for the first time.

Adding Files in PyCharm

The reason we have this main.py file included is because of the checkbox we selected during the project creation step. If we did not do that, or if we want to add additional python files to our project, we can right-click on our project in the “project directory” section and add a new python file from there. In this example, I’m right clicking on “pythonProject” and navigating to New --> Python File:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Starting New Projects in PyCharm

If you open PyCharm again in the future, and the same project keeps opening up automatically, that’s because of the default behavior of PyCharm to attempt to open the last project you were working on. If you want to create a new project, we can use the main menu in PyCharm to “Close our Project”. Once the project is closed, we’ll be met with the PyCharm “Welcome” screen again, where we can open any previously created projects, or we can create a new one.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Python Basics

Now that our PyCharm project is established, let’s alter the placeholder Python code inside main.py with the following:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

The Python “input” function

In this simple program, we’re going to take the user’s input and print out a message to the screen. But what precisely is going to happen, step-by-step?

1. user_input = input()

a. What appears to the right side of an equal sign will always occur first, and its result will then be stored into the variable on the left-hand side of the equal sign.

b. The “input” function is being called here. We know that it’s a function because of the open & close parentheses after the name. We also aren’t passing any parameters to this function.

i. input()is a special type of function, though, which will stop our program entirely and wait for the user to type some text into the program, and then hit ‘Enter’, before continuing with the rest of the program.

ii. That means that our print function will not be executed until our user has entered some text and hit the ‘Enter’ button.

iii. Once they do, whatever they typed before hitting the ‘Enter’ button will be stored as a string (or text) into the user_input variable.

2. print(‘Hello! You typed:’, user_input)

a. This line will simply print the message with the user’s input appended to it, to prove what is being stored in the user_input variable after our input() function is finished

b. Again, this line will not run until the user types some text and hits the ‘Enter’ key

i. The program could wait indefinitely until that occurs!

ii. We can see this happening in the output window in the screenshot above, where our program is still running, but we don’t see anything being output

iii. That’s because it’s waiting for us to type something and hit ‘Enter’

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

iv. Now, I’ve typed ‘banana’ (which PyCharm shows in green text, to denote what is our input vs the program’s output) and when I hit enter, our print statement then got executed, with my input being appended to the message!

Python without PyCharm

To get a better understanding of how Python works, and to show another way that we can interact with Python, I’d like to now show this exact same program we built in PyCharm but using the command line directly, where Python will be used 95% of the time. PyCharm is an amazing tool, and it should be utilized when developing Python code. However, understanding how Python can be used without an IDE can be very useful to know.

NOTE: We’ll be making use of that location (from the PyCharm project creation step), so be sure to have that ready before continuing.

First, we’ll start by opening the Command Prompt program (cmd, command prompt, etc.)

  • By default, the command prompt started me in the “C:\Users\nblai” folder (or directory) but I want to navigate to where my Python file is.
  • To do so, I’ll change my directory (cd) to the location where my python file is.
    • cd C:\Personal\scripts\python\pythonProject
  • On the next line, we can see I’m now in that new directory, and I’m ready to run another command.
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

One of the most direct ways to work with Python is using the python program right from the command line, which is shown in the following screenshot. When we simply type “python” and hit ‘Enter’, we will be brought into an interactive Python window inside our command prompt.

We can write python code line-by-line and each line will be executed immediately. We can use the exit() function and that will take us out of the interactive Python mode and bring us back to our regular command prompt.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Instead of just typing python, we can also provide it the name of a valid python file, and instead of entering an interactive mode, the python file we provided will be executed directly inside our command prompt. Let’s do that now with our main.py file we created in PyCharm.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Now it seems like nothing happened, but that’s because it’s waiting for us to enter some input, since it’s the same program as before when we ran it in PyCharm! Let’s enter some input again and see the output:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Enhancing the “input” function

In order to get some more positive confirmation that our program is running, we can add an additional parameter to the input() function to display a message to the user, so they can know

that they should enter some input, and have more of an idea of what their input should be. Back in PyCharm, let’s adjust our code, and re-run the program, either in PyCharm or from the command line.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Now when our program runs, instead of seeing nothing, we see a message that indicates that we should type something. Besides this change, the program remains the same.

Working with Zybooks

Now that we have a basic understanding of how to use Python & PyCharm, we’ll now make our way to zyBooks to see how it differs from what we’ve learned so far, and how to interpret the zyBooks labs.

ZyBooks Lab Layout

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

A zyBooks lab page consists of 4 main sections:

  • Prompt Area
    • This is the area that contains the instructions for the lab.
    • Be sure to refer to this area all throughout the coding process.
    • Often, you will be given a sample input and expected output for that input.
      • Use this to your advantage. Your program should match their output for the program to be correct.
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
  • Code Area
    • This is where you’ll write your code for the lab.
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
  • Develop/Submit/Input area
    • Develop/Submit Mode toggle
      • This toggle will allow us to switch between develop and submit mode.
      • We should stay in “Develop mode” until we feel our program is complete, which should happen when our output matches what the prompt says the output should be
      • We’ll see more about “Submit mode” later
    • Program Input section
      • This is where we’ll enter any input that our program will need.
      • Since we’re simulating python through the zyBooks lab, in order to be able to type input into the program whenever we use the input() function, it will read each line that’s entered in this input box
        • 1st input() = 1st line in the “Enter program input” box
        • 2nd input() = 2nd line in the “Enter program input” box
        • ....
      • The “optional” can be misleading but it’s optional because not every Python program will need to take user input.
        • However, for nearly every zyBooks lab that we do, we will need to use input, so it’s not really optional for us.
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome
  • Run Program area
    • This button will allow us to run the code that we’ve currently written in the Code section of the lab.
    • Any output from our program will be displayed in the gray box below the “Run Program” button
      • Since we haven’t written any code yet, it lets us know our program doesn’t have any output
Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Using input() in zyBooks

Below is an example using the python input() function, which as we remember, will wait for us to type something into the program and then hit ‘Enter’. But how can we achieve that within zyBooks, where can we type into the program?

That’s where the “Enter program input (optional)” section comes in. Every time our code hits a line that uses the input() function, it will read a line from that input box and simulate us typing that in and hitting ‘Enter’, and then storing the result into our variable.

Notice that we get an error in this first example, though. That’s because we used two input() functions within our code, but only entered 1 line of input in the input box. When we reach the 2nd input() function in the code, it never receives any input, and therefore our program errors with the error we see in the screenshot:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

To fix the error, we’ll add an additional line in the input box to account for the 2nd input() function in our code, and re-run our program to see the result:

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Tip: Do you notice how the input we entered is the same as the input that was mentioned in the prompt for this lab? That will be the case for nearly every lab we do, where we’re provided with some sample input and what it’s expected output is. As a result, we should start each lab by copying the input that they provide into our own input box to test our program and write code that will result in the output they expect!

Submit Mode for Labs

Once we’ve felt that our program is at a point that we feel it is correct, we can navigate to the “Submit mode” section by using the toggle button, where the “Run program” button will turn into a “Submit for grading” button. It’s important to run our program through this section, as this is the only way we can be graded for the labs within zyBooks, since it’s automated through zyBooks itself.

When this button is clicked, multiple different test cases will be run against your program, to ensure that it is correct in several different scenarios (and by scenarios, I mean different inputs that can be entered into the program). To get full credit for a lab, you want to make sure that the output for each of the test cases matches the output that your program has when given the inputs for each test case.

In this first example, none of the test cases passed, and so far, we’ve received a 0. However, don’t fret, as we can re-attempt our grading as many times as we’d like, and we should use the information provided to us by the test cases to help us examine what we might need to change within our code to be correct.

The yellow highlighted text shows us what differs between what our program output and what the output should have been. We can use this information to change our code accordingly to match what output they expect and re-run our “Submit for grading” button to see if we pass any/all of the tests.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

In this next example, we’ve made some code changes and it was able to match the output for the first test case, but the next two still aren’t passing, so our code still doesn’t work in all scenarios. We’ll use the information we receive from the test cases and re-examine and change our code again.

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

In this last example, we’ve made some final changes to our code and used the “Submit for grading” button again to test our changes. This time, all the test cases are passing, and we received a score of 10/10, meaning we received full credit for this zyBooks lab, and we can continue to the next one!

Python Pycharm & Zybooks Guide.pdf - Google Drive - Google Chrome

Need More Help?

Click here to schedule a 1:1 with a tutor, coach, and or sign up for a workshop. *If this link does not bring you directly to our platform, please use our direct link to "Academic Support" from any Brightspace course at the top of the navigation bar.

Previous Article Debugging Best Practices
Next Article Python Data Types - Variables - Input/Output statements (with Video)
Have a suggestion or a request? Share it with us!