| | |
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
Views: 240 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for Python
anti array avogadro beginner builtin clear client code color count csv curved def dictionary dynamic enter examples excel file float format frange ftp function gui heads hints homework import input java lapse line lines linux list lists loop microcontroller mouse multiple mysqldb mysqlquery newb number numbers output parsing path port prime program programming projects py2exe pygame pyopengl pyqt python random raw_input recursion recursive redirect script scrolledtext singleton software sqlite ssh stderr string strings subprocess sum syntax table terminal text thread threading time tkinter tlapse tooltip tuple tutorial twoup ubuntu unicode unix urllib urllib2 variable web-scrape wikipedia windows word wx.wizard wxpython






