Skip to content

Instantly share code, notes, and snippets.

@IanMcT
IanMcT / variables.py
Last active September 22, 2016 14:06
Demonstrates variables
#I McTavish
#Sept 21, 2016
#Variables - demonstrate variables
#Declare an integer variable
my_age = 17
#output my_age
print(my_age)
#output type of data
print(type(my_age))
@IanMcT
IanMcT / 4uconversions.py
Created September 26, 2016 18:46
Demonstrates conversions
def output_variables():
print("w:", w, "Type:", type(w))
print("x:", x, "Type:", type(x))
print("y:", y, "Type:", type(y))
print("z:", z, "Type:", type(z))
w = 3.2
x = 3.8
y = -3.2
z = -3.8
@IanMcT
IanMcT / binaryReadWrite.py
Created September 29, 2016 09:38
Example program that uses a dictionary object and reads and writes to a binary file.
import pickle #used to serialize the data
import os.path
#Comment this code
#global variables
songs_and_bands = {"Drive": "Judge Jackson"}
def open_file():
global songs_and_bands #get global variable
if os.path.isfile('songs_and_bands.dat'):
binary_file=open('songs_and_bands.dat','rb')
@IanMcT
IanMcT / oopics4uunit2_.idea_.name
Created October 3, 2016 10:08
starting code for card game to model OOP.
oopics4uunit2
@IanMcT
IanMcT / grade12oop_.idea_grade12oop.iml
Created October 11, 2016 21:17
Grade 12 War Card Game
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
<option name="PROJECT_TEST_RUNNER" value="Unittests" />
</component>
@IanMcT
IanMcT / if_statements.py
Created October 12, 2016 02:16
Demonstrates if statements
price = float(input("What is the price? "))
#sample if
if price > 100:
print("You qualify for a disount of ",format(price*0.10,".2f"))
#if statement with else
if price < 0:
print("That price is invalid")
else:
print("Proceed with the sale!")
@IanMcT
IanMcT / squares.py
Created October 20, 2016 14:12
Create a program that displays a square using the following pattern rbrbrb bbrbrb rrrbrb bbbbrb rrrrrb bbbbbb
#Name
#date
#goal: create a program that displays a square using the following pattern
"""
rbrbrb
bbrbrb
rrrbrb
bbbbrb
rrrrrb
bbbbbb
@IanMcT
IanMcT / listsexample.py
Created October 28, 2016 09:59
Why we need lists!
#I McTavish
#Oct 28, 2016
#Demonstrate Lists
goals_game1 = 3
goals_game2 = 5
goals_game3 = 2
goals_game4 = 1
goals_game5 = 0
@IanMcT
IanMcT / listsexample2.py
Created October 28, 2016 09:59
Using lists for the first time.
#I McTavish
#Oct 28, 2016
#Demonstrate Lists
goals_game = [3,5,2,1,0]
totalgoals = 0;
for x in range(len(goals_game)):
totalgoals += goals_game[x]
print(totalgoals)
@IanMcT
IanMcT / list_basics.py
Created October 31, 2016 09:28
Basic skills when using lists
#I McTavish
#Oct 27, 2016
#Use Lists
#Create a list of strings
list1 = ['Drew','Sherriee','Lonny','Stacee']
#output full list
print(list1)