VP 10: Python 3 Setup (10 pts)

What You Need

Any computer with Internet access.

Purpose

Get Python 3 working on your system.

Task 1: Try It Online

In a Web browser, go to:
https://tio.run/#python3
In the Code section, enter this code:
print("Hello, World!")
At the top left, click the triangle-in-circle icon to run your code.

The Output section shows the result, as shown below.

Flag VP 10.1: Help (2 pts)

Run this code:
help()
The flag is covered by a green rectangle in the image below.

Using the Network

In the Code section, enter this code:
import requests
r = requests.get("https://samsclass.info")
At the top left, click the triangle-in-circle icon to run your code.

The program fails, with errors, as shown below.

This online Python sandbox doesn't allow sending network traffic. You can use it for some of the challenges, but not all of them.

Task 2: Run Python 3 Locally

A more powerful way to use Python 3 is to install it on your local system.

To see if you already have it, execute this command in a Terminal or Command Prompt window:

python3
If you see a Python version number starting with 3, as shown below, you have Python 3 installed already.

Enter this command to exit the Python interpreter:

exit()

If Python 3 is not already installed, follow the instructions in the gray box below to install it.

Installing Python 3 on a Mac

Follow the instructions below: https://www.maketecheasier.com/using-python-3-on-mac/

Installing Python 3 on Windows

Download te latest version here:
https://www.python.org/downloads/
Start the installer. At the bottom of the first window, check the "Add Python 3.9 to PATH" box, as shown below.

Then click Install Now.

Creating a Program

Follow the instructions in the appropriate gray box below to create and run a simple program.

Linux or Mac

In a Terminal window, execute this command:
nano hello.py
Enter this text, as shown below:
print("HELLO")

Press Ctrl+X, Y, Enter to save the file.

Then execute this command to run the program:

python hello.py
It prints out "HELLO", as shown below.

Windows

In a Command Prompt window, execute this command, as shown below.
notepad hello.py
A box pops up asking "Do you want to create a new file?". Click Yes.

In Notepad, enter this code, as shown below.

print("Hello, World")

In Notepad, click File, Save to save the file.

In the Command Prompt, execute this command, as shown below.

python3 hello.py
The program runs, printing out "Hello, World!", as shown below.

Flag VP 10.2: Requests (8 pts)

Execute this command to install the "requests" library:
python3 -m pip install requests
Then run this program:
import requests
r = requests.get("https://samsclass.info")
print(r.status_code)
The flag is covered by a green rectangle in the image below.


Posted: 6-29-2020
Windows installation updated 6-23-2021