Using Variables

In this project you'll create a program that uses variable to parameterize the execution of code.

Doing the Exercises

The exercises are essential practice for beginning programmers. They are monotonous, yes. But, consider this: I'm a skilled programmer with more than 20 years of experience. I've written tens of thousands of print statements in my life. When I type one in class I do it quickly, without thinking, because I've done it so many times. This enables me to “think past” the line of code I'm writing and it makes programming fun. As a beginner you need a lot of practice before you get there.

When you do the exercises you must perform the study drills and turn in the final product with the project. Here's what should look like when you're done with the exercise (it's been shortened for clarity):

CIS-15 Exercise 4
Michael Matera
Study drill answers 
1. When I change space_in_a_car to 4 from 4.0 the number of people we can transport
changes to 120 from 120.0 
6. When I tried running a computation using variable this happened:
>>> x = y + z 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'y' is not defined
# Assign cars
cars = 100 
# Assign the amount of space in a car
space_in_a_car = 4
# Assign the number of drivers
drivers = 30 

Attach a file header to every file you turn in as discussed in class. Also, when the study drill asks a question be sure to answer it in the file header. You will receive credit for completed drills, so be sure to do them.

Project 2: A Simple Calculation

  • According to Wikipedia the average solar year is
    • 365 days
    • 5 hours
    • 48 minutes
    • 45 seconds

Write a program that calculates the number of seconds in a mean solar year and prints the calculation. Start by storing each of the days, hours, minutes and seconds in a variable. Like this:

days = 365 
hours = 5 

Name your program I will run it like this:

$ python3.6 ./ 
There are exactly 31556925 seconds in a solar year.

Your program should produce output that looks exactly like mine. Be precise! Programs must be.


  • All Python files must have a properly formatted docstring
  • Submit your program in a file called
    • Your program must print only one number, the number of seconds in a solar year
    • You can print any other words you want
    • DO NOT print any other numbers!

Project 2: Advanced (Optional)

If you found project 2 easy. Use the Flask template code that's in this week's lecture notes to make web application that does the solar calculation.

Turn In

You must turn in the following files:

  5. (optional)

You can turn them in using a single zip file or separately. But the names must match exactly or there will be a deduction in points.


  • 5 points for the exercises
  • 5 points for correctness of the submission (filenames, etc)
  • 10 points for the correctness of the program
    • There must be a proper file header
    • The program must execute and produce the desired output