On Thu, Feb 25, 2010 at 11:16:09AM +0100, GewoonAnthony wrote:
> Hallo,
> 
> Ik ben een newbie in Python (en voor het eerst programmeren) en zit
> met de volgende (simpele) uitdaging, maar ik zie het licht even niet.
> Wie kan mij helpen?
> 
> Ik wil graag tabeldata gebruiken die alsvolgt is opgebouwd:
> 
> Bedrag                          percentage
> 15000     -   16500          25%
> 16500     -    23000         30%
> 
> etc

Iets als dit?

maur...@kronos:~ $ python
Python 2.4.6 (#2, Mar 19 2009, 10:00:53) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> amounts = [(0, 0), (15000, 25), (16500, 30), (23000, 35)]
>>> def rebate(amount):
...     chosen = 0
...     for number, percentage in amounts:
...         if amount < number:
...             break
...         chosen = percentage
...     return chosen
... 
>>> rebate(-5)
0
>>> rebate(0)
0
>>> rebate(100)
0
>>> rebate(15000)
25
>>> rebate(16000)
25
>>> rebate(16499)
25
>>> rebate(16500)
30
>>> rebate(23000)
35
>>> rebate(10000000000)
35

-- 
Maurits van Rees | http://maurits.vanrees.org/
            Work | http://zestsoftware.nl/
What are you going to create today?
_______________________________________________
Python-nl mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-nl

Antwoord per e-mail aan