cs259 ยป

CS259 Lesson2 Code

CS259 Lesson2-6 Code is


import math
import random

def square_root(x):
    assert x >= 0
    y = math.sqrt(x)
    assert y * y == x
    return y

for i in range(1, 1000):
    r = random.random() * 10000
    z = square_root(r)

print 'Done!'

CS259 Unit2-9 Code is


import sys
import readline


def remove_html_markup(s):
    tag   = False
    quote = False
    out   = ""

    for c in s:
        if c == '<' and not quote:
            tag = True
        elif c == '>' and not quote:
            tag = False
        elif c == '"' or c == "'" and tag:
            quote = not quote
        elif not tag:
            out = out + c

    assert out.find('<') == -1
    return out

CS259 Unit2-12 Code is


class Time:
    def __init__(self, h = 0, m = 0, s = 0):
        self._hours   = h
        self._minutes = m
        self._seconds = s

    def hours(self):
        return self._hours

    def minutes(self):
        return self._minutes

    def seconds(self):
        return self._seconds

    def __repr__(self):
        return "{:02d}:{:02d}:{:02d}".format(
            self.hours(), self.minutes(), self.seconds())

t = Time(13, 0, 0)
print t