Intro to Python

Or the super secret language to use for your assignments

Anas Ambri

November 2014

In preparation


Currently working at Guestful as mobile developer

Also, 6th year COEN student

(yes, it's been a while)

For these slides:

Who are you?

Show of hands

Why Python?

  • Can be learned in a holiday

  • Perfect for assignments 

    • AI class

    • CS Games

  • Multi-purpose


import os

os.system('"sudo make_sandwich"')

What is Python?

  • Interpreted

  • Dynamic

  • Cake and cherry on the cake

name = "Michael"  #Most used male name in Canada in 1990
print "\n".join(map(lambda x: "Happy Birthday to " 
                      + ("you" if x != 2 else name),range(4)))


Live coding



Write a program that prints the numbers from 1 to 100. But for multiples of 3 print “Fizz” instead of the number and for the multiples of 5 print “Buzz”. For numbers which are multiples of both 3 and 5 print “FizzBuzz”.

For the one guy who can cure Cancer with Python: do it without if-conditionals


Random Insults


Create a class named `Insultor` that has a method `insult` that returns an insult.

An insult is the concatenation of three strings, selected from a list that we pass when we construct the object



  • Pass the list as input (check raw_input)
  • Selecting the strings can be done randomly
input = raw_input("Enter another insult word. Otherwise press enter")
while(input != "\n"):
    # Do something with input
    input = raw_input("Enter another insult word. Otherwise press enter")

import random
print random.randint(0,9)

Where to go from here?

Or just go home