Skip to content

Instantly share code, notes, and snippets.

View chicagowebmanagement's full-sized avatar

Patrick Elward chicagowebmanagement

View GitHub Profile
import math
class Hexagon:
def __init__ (self, side):
self.perimeter = (side*6)
self.side = side
hex1 = Hexagon(16)
print (hex1.perimeter)
@chicagowebmanagement
chicagowebmanagement / triangle-class.py
Last active October 2, 2019 22:47
create a class triangle and get its area.
"""
Author: Patrick Elward
Date: 10/02/2019
training on OOP with getting area of triangle.
THIS WAS NOT WORKING RIGHT in april, but i came back to fix it!
"""
@chicagowebmanagement
chicagowebmanagement / write-test.py
Last active August 21, 2019 16:41
testing of Ryan Elam's code
import csv
with open("testingme.csv","w") as csvfile:
write=csv.writer(csvfile, delimiter=",")
write.writerow (["Top Gun", "Risky Business", "Minority Report"])
write.writerow (["Titanic", "The Revenant", "Inception"])
@chicagowebmanagement
chicagowebmanagement / rectangle-square.py
Last active May 20, 2019 16:35
Create two classes, rectange and square and display the perimeter of each
"""
Author: Patrick Elward
Date: 04/28/2019
Create Rectangle and Square classes with a method called calculate_perimeter that calculates the perimeter of the shapes they represent.
Create Rectangle and Square objects and call the method on both of them.
"""
import math
@chicagowebmanagement
chicagowebmanagement / myclass.py
Last active May 15, 2019 00:00
quick testing of class
"""
Author: Patrick Elward
Date: 05/06/2019
continued testing of classes
"""
class MyClass:
def __init__(self):
print('object ',self,' constructed')
@chicagowebmanagement
chicagowebmanagement / error-classes-review.py
Last active May 14, 2019 23:27
trying to understand classes better
"""
ERRORS
A. print(Triangle.mytriangle_area(self)) = NameError: name 'self' is not defined
B. print(Triangle.mytriangle_area()) = TypeError: mytriangle_area() missing 1 required positional argument: 'self' (SEE LINE with comments BELOW)
C. print(Triangle.mytriangle_area) = prints out '<function Triangle.mytriangle_area at 0x7f8f1a5fb620>'
"""
# ----------------------------------------------
import math
@chicagowebmanagement
chicagowebmanagement / rectangle-square-testing.py
Last active May 3, 2019 17:11
create classes and execute them
"""
Author: Patrick Elward
Date: 05/03/2019
Create Rectangle and Square classes with a method called calculate_perimeter that calculates the perimeter of the shapes they represent.
Create Rectangle and Square objects and call the method on both of them.
"""
import math
@chicagowebmanagement
chicagowebmanagement / flicks.py
Last active May 2, 2019 15:27
create a csv from within python list of lists
"""
Author: Patrick Elward
Date: 04/18/2019
Take the items in this list of lists: [["Top Gun", "Risky Business", "Minority Report"], ["Titanic",
"The Revenant", "Inception"], ["Training Day", "Man on Fire", "Flight"]] and write them to a CSV file.
The data from each list should be a row in the file, with each item in the list separated by a comma.
flicks.csv then shows this:
Top Gun,Risky Business,Minority Report
@chicagowebmanagement
chicagowebmanagement / hexagon.py
Last active April 29, 2019 00:49
Create a hexagon class and calculate its area
"""
Author: Patrick Elward
Date: 04/28/2019
Make a Hexagon class with a method called calculate_perimeter that calculates and returns its perimeter.
Then create a Hexagon object, call calculate_perimeter on it, and print the result.
"""
import math
@chicagowebmanagement
chicagowebmanagement / circle-2.py
Last active April 29, 2019 00:42
create a simple circle and output the area
"""
Author: Patrick Elward
Date: 04/26/2019
Create a Circle class with a method called area that calculates and returns its area.
Then create a Circle object, call area on it, and print the result.
Use Python's pi function in the built-in math module.
import math