Skip to content

Instantly share code, notes, and snippets.

View johnmcc's full-sized avatar

John McCollum johnmcc

  • Glasgow, Scotland
View GitHub Profile

Polymorphism - Minilab

  • create an 'InternetRadio' class which implements the IConnect interface and be able to add an instance to Network
  • make the radio be able to tune to a station
  • give the Network a maximum number of items that can be connected to it
  • add a method to our Network to tell how many many free connection 'slots' there are.
  • modify the connect() method in the Network class so that it will check if there are any free slots before a device can connect.

OOP Lab

Acme, Inc. has provided you with a CSV file containing the following fields for a number of orders:

  • region
  • country
  • item_type
  • sales_channel
  • order_id
  • units_sold (int)
@johnmcc
johnmcc / lab.py
Last active April 20, 2018 13:46
# Meet the Beatles:
beatles = [
{"name": "John Lennon", "birth_year": 1940, "death_year": 1980, "instrument": "piano"},
{"name": "Paul McCartney", "birth_year": 1942, "death_year": None, "instrument": "bass"},
{"name": "George Harrison", "birth_year": 1943, "death_year": 2001, "instrument": "guitar"},
{"name": "Ringo Starr", "birth_year": 1940, "death_year": None, "instrument": "drums"}
]
# Use the `beatles` list above to answer the following questions:

Part 1

Using a loop, and the following list:

ages = [5, 15, 64, 27, 84, 26]
  • Find the sum total of the values in this list
  • Find the average (mean) value of the items in the list

https://docs.python.org/3/tutorial/datastructures.html

Using the documentation for list methods, complete the following tasks:

Add "Queen Street" to the start of the list

Find out what index "Croy" is at in the list

Add "Polmont" at the appropriate point (between "Falkirk High" and "Linlithgow")

stops = ["Croy", "Cumbernauld", "Falkirk High", "Linlithgow", "Livingston", "Haymarket"]

Online Shop.

Model an online shop.

You are tasked with creating an e-commerce platform. Your online store may sell anything you wish. It could be a niche, boutique store or a more general 'amazon' type. Customers will log in, add items to their basket and purchase them.

Your shop should include; A stock class with quantity, price and availability.

# USE THIS SCRIPT AT YOUR OWN RISK
# Make sure your work is backed up / in version control.
# Quick and dirty script to recursively replace all
# headers of the format ###heading with ### heading.
# (Works through all .md files in the directory, and subdirectories)
filelist = Dir.glob("**/*.md")
for filename in filelist

Java problems.

Choose one:

Task 1

  • Write a guessing game where the user has to guess a secret number.
  • After every guess the program tells the user whether their number was too large or too small.
  • At the end the number of tries needed should be printed.
@johnmcc
johnmcc / gist:5747325
Created June 10, 2013 08:44
Create zip archive with changes between two commits.
git archive -o latest.zip later-commit $(git diff --name-only earlier-commit later-commit)