To set up a virtual machine (VM) on Google cloud. This will allow you to have a command-line machine for doing the labs and projects for this course.
The instructions for setting up your Google Cloud account, and creating a virtual machine, are on the CPSC 225 page. You can find the instructions here:
Follow the linked instructions through the "Connecting with a Client" section.
Once you have this setup, you should be able to use it to write and execute Python scripts. In order to test this, you should write a short script to display the current whether in Fredericksburg.
To do this open a file called lab1.py with Vim, and enter the following short program:
import urllib.request import urllib.parse url = "http://wttr.in/Fredericksburg?format=3" data = urllib.request.urlopen(url) print(data.read().decode("utf-8"))
This uses the Python urllib library which is for requesting data from URLs. This program uses the library to request data from the given URL and print it to the screen. wttr.in is a web service which provides weather information.
You should run this with the command:
$ python3 lab1.py Fredericksburg: ☀️ +42⁰F
Your output will be different depending on the weather!
For this lab, you should change the program so that it asks the user to enter the location as input, and then display the weather in that location instead of always doing Fredericksburg. To do this, you'll need to do the following:
When you run the program when you're done it should work like this:
$ python3 lab1.py Enter a city: Sydney Sydney: ⛅️ +73⁰F $ python3 lab1.py Enter a city: Anchorage Anchorage: ☀️ +18⁰F
When your program works, email the lab1.py file to firstname.lastname@example.org. Please attach it as a file instead of copying it into the body of the message!
If you need help getting the .py file off of your VM, you can see how to do it here:
Copyright © 2018 Ian Finlayson | Licensed under a Creative Commons Attribution 4.0 International License.