Class 1 Lab 2 ‐ Comments & Print - Justin-Boyd/Python-Class GitHub Wiki

Task 1: Become Familiar with Python Code

Step 1

  • In PyCharm, click the main.py file to display it

Step 2

  • Click the red dot on line 9 to remove it (it is related to code debugging, which is not covered in the course).

Step 3

  • Execute the script by clicking the green arrow at the top left corner of the window. Note that the result of the execution is the text Hi, PyCharm.

Step 4

  • In the file, locate the word PyCharm and change it to your name.

Step 5

  • Run the file again, and note that the output this time is your name.

Step 6

  • Note that the word Hi is not in the same line as the name. Locate the word Hi in the file command that prints the text.

Step 7

  • Think about the script’s execution path. What do you think happens there?

Task 2: Hello World!

Step 1

  • Create a new Python file and name it Hello_World.

Step 2

  • Write a command to print the text Hello World! using the print("Hello World!") function.

Step 3

  • Run the script by clicking the green arrow. Note that the output does not match the content of the file. What do you think happened?

Step 4

  • To make PyCharm execute the currently viewed file, right-click its content and select Run ‘Hello_World’

Step 5

  • Add a comment to the code using # with the following text after it: This program will print to the console the string “Hello World!”

Step 6

  • Execute the file again and note that the content of the comment does not affect the output.

Step 7

  • What are comments used for when writing scripts and programs?

Step 8

  • Create a new file in the project and write a line of code to print the text I’m a Programmer. Use three quotation marks (“”” text “””) to describe how to create a new Python file, and run it using Ctrl + Shift + F10.