Skip to content

Instantly share code, notes, and snippets.

<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="W29" />
<option value="E501" />
</list>
</option>
@IanMcT
IanMcT / ics4ucomplex.py
Created November 1, 2016 09:40
Demonstrates using an array of a complex data type.
#I McTavish
#Oct. 2016
#Demonstrate arrays with complex data types
class Aliens:
"""Aliens class - represents an alien in a video game"""
def __init__(self, x, y):
"""x, y are the starting positions"""
self.x = x
self.y = y
self.speed = 10
@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)
@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 / 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 / windowbutton.py
Last active September 26, 2020 22:01
Code for a windows program that takes input, runs code when button pressed output is created. Modify so anything over 300km has added output: Geez, that is far. Anything less than 50 km - Short trip!
#Ian McTavish
#July 26, 2016
#Create a window with an Entry widget
#import required libraries
import tkinter
import tkinter.messagebox #needed for messagebox
class MyGUI:
"""Graphics class"""
@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 / 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 / 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 / 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!")