VP 11: Python in Google Colab (10 pts)

What You Need

Any computer with Internet access.

Purpose

Get Python 3 working on the free Google Colab system.

Using Google Colab

In a browser, go to
https://colab.research.google.com/
If you see a blue "Sign In" button at the top right, click it and log into a Google account.

From the menu, click File, "New notebook".

In the Code box next to the circled arrow, enter this code:

print("Hello, World!")
At the left, click the circled arrow icon to run your code.

The words "Hello World" appear below the code, as shown below.

Flag VP 11.1: Help (2 pts)

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

Click the Run button to stop help().

Using the Network

Execute the code below to install the "requests" library and run it to load my Web page.

The third line performs a GET request to load my Web page and puts the reply in a variable named "r".

!pip install requests
import requests
r = requests.get("https://samsclass.info")
print()
print(dir(r))
At the top left, click the triangle-in-circle icon to run your code.

The library is already installed, so the output shows "Requirement already satisfied" messages.

The last line shows all the possible methods available to examine the reply named "r".

Scroll to the right to see the last three methods, as shown below.

Flag VP 11.2: Requests (8 pts)

Execute this code to see some parts of the reply:
print( r.status_code )
print( r.url )
The flag is covered by a green rectangle in the image below.


Posted: 6-27-23