This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def kilobytes(bytes): | |
kb = round(bytes / 2**10, 1) | |
return str(kb)+"KB" | |
def megabytes(bytes): | |
mb = round(bytes / 2**20, 1) | |
return str(mb)+"MB" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
This program prints an ASCII table. | |
""" | |
start = 32 | |
end = 127 | |
columns = 8 | |
rows = int((end - start + 1) / columns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Sample code to demonstrate reading a list of objects from a file""" | |
from people import * | |
database_list = [] | |
# Add Staff from file to the database list until there's no text left. | |
file = open("staff.txt", "r") | |
while True: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import untangle | |
from datetime import datetime | |
class IrishRail: | |
def __init__(self, station="MLLOW", minutes=6): | |
self.station = station | |
self.minutes = minutes | |
self.url = "http://api.irishrail.ie/realtime/realtime.asmx/getStationDataByCodeXML_WithNumMins?StationCode={}&NumMins={}".format(self.station, self.minutes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Ball: | |
def __init__(self, x, y, radius, direction="none"): | |
self.x = x | |
self.y = y | |
self.radius = radius | |
self.direction = direction | |
def move(self): | |
if self.direction == "left": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Fetches BitCoin price from CoinDesk | |
# https://www.coindesk.com/price/ | |
# Code adapted from https://github.com/dursk/bitcoin-price-api | |
import requests | |
def get_price(currency='USD'): | |
url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json'.format(currency) | |
response = requests.get(url) | |
response.raise_for_status() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import datetime | |
class Drone: | |
"""Defines the Drone class.""" | |
def __init__(self, name="drone", x_position=0, y_position=0, power=100, radius=15, colour=[255,255,255], thickness=3): | |
self.name = name | |
self.x = x_position | |
self.y = y_position | |
self.p = power |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
meetings = {"hardware": ["Paul", "Mairin", "Natasha", "John", "Pat"], | |
"networks": ["Pat", "Niall", "Bernie", "Eoin"], | |
"operating systems": ["Natasha", "Eoin", "Michael", "Regina"], | |
"programming": ["Mairin", "Michael", "Rosemary", "Mary", "Ray", "Maura", "Joan", "Sheena"], | |
"object oriented": ["Natasha", "Eoin", "Michael", "Maura", "Guy"], | |
"software architecture": ["Natasha", "Eoin", "Maura"], | |
"virtualisation": ["Natasha", "John", "Pat", "Regina", "Mary"], | |
"mobile technologies": ["Rosemary", "Ray"], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Conversion Functions | |
Eoin Ó Spealáin | |
October 2017 | |
""" | |
def c_to_f(temperature): | |
"""Converts temperature from Celsius to Fahrenheit.""" | |
f = temperature * 9/5 + 32 | |
return f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
from turtle import * | |
biro = Turtle() | |
biro.color("purple", "yellow") | |
biro.speed(0) | |
def petal(): | |
biro.begin_fill() |
NewerOlder