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 / animation_if.py
Created October 11, 2016 02:10
Animates two balls that bounce on the screen.
#import libraries
#Uses http://stackoverflow.com/questions/13215215/python-tkinter-animation
import tkinter
#Set width, height, frames per second and how long to cross
CANVAS_WIDTH = 800
CANVAS_HEIGHT = 600
FPS = 120
SECONDS_TO_CROSS = 1.5
@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 / bank_account.py
Created October 14, 2016 17:23
oop conceps
class BANK_ACCOUNT:
"""Bank account
has balance, and withdraw and deposit functions"""
def __init__(self):
self.balance = 0
def deposit(self, amount):
"""adds money to the balance"""
self.balance += amount
def __str__(self):
return "Balance is: $" + str(format(self.balance,".2f"))
@IanMcT
IanMcT / random_circles.py
Created October 19, 2016 14:38
Create random circles on the screen
#Name
#date
#goal: create a program that displays random circles on the screen
import tkinter#Library
import random #Library for random numbers
#Global variables
CANVAS_WIDTH = 800
CANVAS_HEIGHT = 600
@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