Zdravim,

Jakub Vojáček napsal(a):
> Ale těch "if" by bylo spoustu a mohl bych v nich udělat chybu. Spíš by to 
> chtělo něco funkci:
> def usu(self,uhel1,strana,uhel2):
>     #pocitani
>     #return hodnoty
>   
Ano, ve fci "pocitej" by mel byt slozeny if, ktery by rozdelil problem a 
volal by jednotlive fce pro sss, sus, a usu. Nebo mozna neco podobneho 
tomuto:

    class triangle:
        def sss(self, input):
            ...
            return input
           
        def sus(self, input):
            ...
            return input
           
        def usu(self, input):
            ...
            return input
       
        def pocitej(self, input, typ):
            if typ in ('sss', 'sus', 'usu'):
                return getattr(self, typ)(input)
            else:
                raise InvalidType('something')


> tato funkce může spočítat velikosti zbývajicích stran, ale neví, jestli je 
> tohle strana "a", nebo "b". Proto bych potřeboval poradit jakým způsobem 
> tohleto řešit, jestli nakonec nebudu muset psát řešení pro každou možnou 
> variantu. Snad jsem to vysvětlil dobře .
>   
Priklad pro usu:

    from math import sin, radians

    #setup
    sides = ('a', 'b', 'c')
    angles = ('alpha', 'beta', 'gamma')
    mapping = {}
    for i in range(len(sides)):
        mapping[sides[i]] = angles[i]

    #input
    data = {'b': 5, 'beta': 15, 'gamma': 60}

    #filtering
    inpSide = filter(lambda x:x in data, sides)[0]
    inpAngles = filter(lambda x:x in data, angles)
    remSides = filter(lambda x:x not in data, sides)
    remAngle = filter(lambda x:x not in data, angles)[0]

    #calculating
    data[remAngle] = 180 - sum(map(lambda x:data[x], inpAngles))
    for side in remSides:
        inpSideSin = sin(radians(data[mapping[inpSide]]))
        sideSin = sin(radians(data[mapping[side]]))
        data[side] = round(data[inpSide]/inpSideSin * sideSin, 2)

    #printing
    print 'Input:\n\tSide: %s\n\tAngles: %s' % (repr(inpSide), inpAngles)
    print 'Calc:\n\tSides: %s\n\tAngle: %s' % (remSides, repr(remAngle))
    print 'Result:\n\t%s' % data

Myslim, ze by to chtelo pridat jeste nejake kontroly, jestli je vsechno 
zadano jak ma.
> Děkuju za každou pomoc a sory že otravuju, ale už fakt nevim:(:(
>   

Doufam, ze jsem trosku pomohl. Je mozne, ze by slo vse spojit do jedne 
fce, ale uz je moc pozde a mne se nechce premyslet ;-).
Leo

-- 
----
Leos Pol
SW Engineer
Radiante Corp.

If it can be imagined,
we can implement it

_______________________________________________
Python mailing list
[email protected]
http://www.py.cz/mailman/listinfo/python

Odpovedet emailem