If the version of your code on github does not run, it is considered non-functioning. If it does not run on your personal computer WITHOUT CHANGES, it is considered non-functioning.
WARNING: Graders will not grade any part of your code that does not execute.
TOTAL: 20 points
In this lab, you will learn to:
For this lab we are going to work with simple Python data. Open the lab folder’s in Ch01 and add the following code to your main.py
if not already present:
#Part A
weeks = 16
classes = 5
tuition = 6000
cost_per_week = ((tuition / classes) / weeks)
print("Cost per week:", cost_per_week)
You must keep the format, indentation, and capitalization EXACTLY as it is!
classes_per_week
.
cost_per_week
by the classes_per_week
and save the result in a variable called cost_per_class
cost_per_class
to the console with a nice message of your choiceprint(var, type(var)) #'var' is the variable name
Before we continue writing code for this lab, we need to introduce Python modules.
Modules allow us to use additional Python library code to quickly accomplish complex tasks. There are lots of different modules that we will be using over the course of the semester. One module that you will find useful is called random.
The random module allows Python to generate random numbers (we say pseudo because computers can’t generate truly random numbers). Add the following to the top (the first line) of your main.py script:
import random
You can now use the commands from the module in your program. For example, if I wanted to print out a random number between 1 and 10 (non-inclusive), I could use the command:
random.randint(1,10)
Another command from the random module is random.choice(), which allows you to give it a list and return a random object from the list.
You can name the following variables anything you like, as long as you follow the style guidelines at the end of this document.
All code for this lab codes into the folder: ch01/lab
, which should have the following path:
ch01/
lab/
main.py
commit your changes and push your code back to Github.
Complete your submission by making a commit and push using either the Source Control tab in VSCode or the command line in the shell
REMINDER: Submission instructions from Lab 0
Go to your repo on Github to verify your changes were pushed. If your changes are there, that's it! You've completed the work for this lab.