Session 1: Homework

Complete all sections.

  1. Create a directory called CM6111 in your home directory (folder with your username)
  2. Inside, create three folders:
    1. assignments - where all homeworks and coursework will be saved
    2. lectures - where all lectures will be saved
    3. work - space for your own work, either as a Python script or a Jupyter notebook
  3. Enter the work directory and write out the following code into a file called age.py, filling in the blanks:

In [3]:
name = "<YOUR NAME HERE>"
current_year = 2016
year_of_birth = 1989 #add your age here
age = str(current_year - year_of_birth)
print("Hello")
print(name)
print("You are: " + str(current_year - year_of_birth))


You are: 27

Run the above code using python age.py in your command prompt/terminal

  1. When will the above code be wrong?
  2. How would you fix that?
  3. Why is there a + between "You are" and the age?
  4. What do you think the str stands for on the last line? Why is it there?
  1. When the year changes
  2. Use the Python package for datetime
  3. To concatenate the two strings
  4. It converts the int to a string so they can be concatenated