Exemple #1
0
def exemplo(titulo, metodo, equacoes):
    print '[{0}]'.format(titulo)
    for e in equacoes:
        print 'Equação: {0}'.format(e[0])
        for args in e[1]:
            calc.aplicar(metodo, eq(e[0]), *args)
        print
Exemple #2
0
def _entrada(msg, tipo, *opts):
    if tipo == 'opt':
        for k, opt in enumerate(opts[0]):
            print '{0}. {1}'.format(k + 1, opt[1])
        inp = raw_input(msg + ': ')
        try:
            return opts[0][int(inp) - 1][0]
        except ValueError:
            for opt in opts[0]:
                if opt[1].lower().startswith(inp.lower()):
                    return opt[0]
            raise ValueError
    else:
        inp = raw_input(msg + ': ')
        if tipo == 'int':
            return int(inp)
        if tipo == 'float':
            return float(inp)
        if tipo == 'floatarray':
            inp = inp.translate(None, '[](),')
            return map(lambda t: float(t), inp.split())
        if tipo == 'eq':
            return eq(inp)