| | |
having trouble with a mathmatical function
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2009
Posts: 50
Reputation:
Solved Threads: 16
lets say i have 2 lists:
lista = [1,2,3,5,6,7]
listb = [4,5,6,7,8,9,10]
The lists can be different lengths, and may not allways be unequal lengths.
The higher average will allways be in listb, so that is the 1 constant we can rely on.
This works for even teams:
value would return the number i needed to move from listb to lista
i tried this,but it doesnt seem to work:
any ideas?
lista = [1,2,3,5,6,7]
listb = [4,5,6,7,8,9,10]
The lists can be different lengths, and may not allways be unequal lengths.
The higher average will allways be in listb, so that is the 1 constant we can rely on.
This works for even teams:
Python Syntax (Toggle Plain Text)
average = float(sum(lista) + sum(listb)) / \ float(len(lista) + len(listb)) value = round(abs((average * len(lista)) - sum(lista)))
value would return the number i needed to move from listb to lista
i tried this,but it doesnt seem to work:
Python Syntax (Toggle Plain Text)
Offset = float(len(listb) - len(lista)) value = round(((len(lista) * sum(lista)) + \ (len(lista) * Offset) - \ (average * len(lista) - \ (average * Offset))) / \ (len(lista) * Offset))
any ideas?
0
#4 Oct 7th, 2009
You are getting tangled up in a forest of parenthesis. There is one missing in the mess. It is best to break things into smaller parts ...
python Syntax (Toggle Plain Text)
list_a = [1,2,3,5,6,7] list_b = [4,5,6,7,8,9,10] # for convenience list_ab = list_a + list_b average = float(sum(list_ab))/len(list_ab) offset = float(len(list_b) - len(list_a)) a = len(list_a) * sum(list_a) b = len(list_a) * offset c = average * len(list_a) d = average * offset value = (a + b - c - d)/b print value print round(value)
Last edited by vegaseat; Oct 7th, 2009 at 10:58 am.
May 'the Google' be with you!
![]() |
Similar Threads
- Trouble calling VB function from C DLL (Visual Basic 4 / 5 / 6)
- recursion function (C++)
- a function that scans a word returning bits (C++)
- help! generate random word function from fiveLetter.txt file (Python)
- Having trouble understanding how header files work. (C++)
- Using the sleep function (Java)
- problem with system() function... (C++)
- Function help/homework (C++)
- Help making a function (Python)
Other Threads in the Python Forum
- Previous Thread: Primes
- Next Thread: Need help with conditional
| Thread Tools | Search this Thread |
Tag cloud for Python
alarm assignment avogadro beginner bluetooth character cmd code copy customdialog cx-freeze data decimals dictionary directory dynamic error examples excel exe file float format ftp function generator gnu graphics gui halp homework http ideas import input itunes java leftmouse line linux list lists logging loop module mouse number numbers output parsing path port prime program programming projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext slicenotation sqlite ssh stdout string strings sudokusolver table terminal text thread threading time tkinter tlapse tuple tutorial ubuntu unicode update urllib urllib2 variable ventrilo verify vigenere web webservice wikipedia windows wxpython xlib






