Exemplo n.º 1
0
def exercise(name="Ariel"):
    print(">>> gizmo.hello('Gizmo', 'Germany')")
    gizmo.hello('Gizmo', 'Germany')
    print(">>> gizmo.hello('Gizmo')")
    gizmo.hello('Gizmo')

    print(">>> gizmo.spell('hello')")
    gizmo.spell('hello')


    print(">>> print(gizmo.relative_path(['subject1', 'subject2']))")
    print(gizmo.relative_path(['subject1', 'subject2']))

    print(">>> giz = gizmo.Gizmo(name='Ariel')")
    giz = gizmo.Gizmo('Ariel')

    print(">>> print(giz)")
    print(giz)

    print(">>> print(giz.name)")
    print(giz.name)

    print(">>> giz.speak()")
    giz.speak()

    print(">>> print(gizmo.multiplication_table())")
    print(gizmo.multiplication_table())

    print(">>> print(gizmo.multiplication_table(zero_out_multiples=5))")
    print(gizmo.multiplication_table(zero_out_multiples=5))

    print(">>> fib = gizmo.generate_fibonacci_sequence(10)")
    fib = gizmo.generate_fibonacci_sequence(10)

    print(">>> while(True): print(next(fib))")
    try:
        while(True): 
            print(next(fib))
    except StopIteration:
        pass

    print(">>> print(gizmo.get_fibonacci_sequence(10))")
    print(gizmo.get_fibonacci_sequence(10))

    print(">>> print(gizmo.get_titanic().head(5))")
    print(gizmo.get_titanic().head(5))

    print(">>> print(gizmo.get_titanic_children())")
    print(gizmo.get_titanic_children())
Exemplo n.º 2
0
def test_ex9():
    """Ex9: Use Numpy's fancy indexing"""
    import numpy as np
    from numpy.testing import assert_equal
    import gizmo
    assert hasattr(gizmo, 'multiplication_table')
    assert hasattr(gizmo.multiplication_table, '__call__')
    prod_table = gizmo.multiplication_table()
    assert type(prod_table) == np.ndarray
    ref_table = np.outer(np.arange(1, 13), np.arange(1, 13))
    assert_equal(prod_table, ref_table)

    # Test zero_out_multiples parameter
    assert_equal(prod_table, gizmo.multiplication_table(None))
    prod_table_without_3 = gizmo.multiplication_table(zero_out_multiples=3)
    assert type(prod_table_without_3) == np.ndarray
    ref_table_without_3 = ref_table.copy()
    ref_table_without_3[ref_table_without_3 % 3 == 0] = 0
    assert_equal(prod_table_without_3, ref_table_without_3)
Exemplo n.º 3
0
def test_ex8():
    """Ex8: Add a NumPy array"""
    import numpy as np
    from numpy.testing import assert_equal
    import gizmo
    assert hasattr(gizmo, 'multiplication_table')
    assert hasattr(gizmo.multiplication_table, '__call__')
    prod_table = gizmo.multiplication_table()
    assert type(prod_table) == np.ndarray
    ref_table = np.outer(np.arange(1, 13), np.arange(1, 13))
    assert_equal(prod_table, ref_table)
Exemplo n.º 4
0
def test_ex9():
    """Ex9: Use Numpy's fancy indexing"""
    import numpy as np
    from numpy.testing import assert_equal
    import gizmo
    assert hasattr(gizmo, 'multiplication_table')
    assert hasattr(gizmo.multiplication_table, '__call__')
    prod_table = gizmo.multiplication_table()
    assert type(prod_table) == np.ndarray
    ref_table = np.outer(np.arange(1, 13), np.arange(1, 13))
    assert_equal(prod_table, ref_table)

    # Test zero_out_multiples parameter
    assert_equal(prod_table, gizmo.multiplication_table(None))

    # We don't check 0, it's fine to let it raise exceptions in that case
    for n in range(1, 13):
        prod_table_without_n = gizmo.multiplication_table(zero_out_multiples=n)
        assert type(prod_table_without_n) == np.ndarray
        ref_table_without_n = ref_table.copy()
        ref_table_without_n[ref_table_without_n % n == 0] = 0
        assert_equal(prod_table_without_n, ref_table_without_n)
Exemplo n.º 5
0
gizmo.spell('word')

#%%
#ids = ['subj1','subj2']
ids = 'subjx'
paths = gizmo.relative_path(ids)
print(paths)

#%%
from gizmo import Gizmo

g = Gizmo('Mabelle')
g.speak()

#%%
t = gizmo.multiplication_table()
print(t)

#%%
print(gizmo.multiplication_table.__doc__)

#%%
fib = gizmo.generate_fibonacci_sequence(7)
for f in fib:
    print(f)

#%%
f = gizmo.get_fibonacci_sequence(5)
print(f)

#%%