Skip to content

Instantly share code, notes, and snippets.

@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 / 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)
@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
<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 / address_book.py
Created November 2, 2016 13:55
Modify based on comments
#Name
#Date
#Add global variable - a list of addresses
#open button should open a set text file
#and load addresses
#close should save using the list
#When open first item displayed
#next moves to next item
import tkinter
@IanMcT
IanMcT / temp_converter.py
Created November 7, 2016 01:50
Demonstrates how to use methods in a program.
#I McTavish
#Nov 2, 2016
#Demonstrate methods with temp convertor
def convert_c_to_f(c):
"""Method to convert Celsius to Fahrenheit
Pre: Celsius temp
Post: Fahrenheit temp"""
f = 9/5*c+32
return format(f,".2f")
@IanMcT
IanMcT / hangman_template.py
Created November 7, 2016 11:02
Template for hangman game.
#I McTavish
#Nov 3, 2016
#Create a template for hangman game.
import tkinter
from tkinter import font
class MyGUI:
"""The class that handles the window"""
def __init__(self):
#main window
@IanMcT
IanMcT / hangman_template.py
Created November 7, 2016 11:04
Modified a comment.
#I McTavish
#Nov 3, 2016
#Create a template for hangman game.
import tkinter
from tkinter import font
class MyGUI:
"""The class that handles the window"""
def __init__(self):
#main window