check this thread https://python-forum.io/Thread-Homework-...ing-System
we had nice discussion on similar issue - no need to use huge if/else block
we had nice discussion on similar issue - no need to use huge if/else block
def get_value(node, percent): breakpoints = {'v':((25, 0), (50, 2), (75, 5), (100, 10)), 'r':((25, 10), (50, 5), (75, 2), (100, 1))} if not 0 <= percent <= 100: raise ValueError('Ivalid percent value. Expected 0-100, got {}.'.format(percent)) try: for breakpoint, value in breakpoints[node]: if percent <= breakpoint: return value except KeyError: raise KeyError('Not a valid node value {}.'.format(node)) nodes=['v', 'r', 'r', 'v', 'r', 'r', 'r', 'r', 'v', 'v', 'r', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v', 'v'] percents=[5.0, 10.0, 15.0, 20.0, 25.0, 30.0, 35.0, 40.0, 45.0, 50.0, 55.0, 60.0, 65.0, 70.0, 75.0, 80.0, 85.0, 90.0, 95.0, 100.0] # percents = range(5, 101, 5) points = [get_value(node, percent) for node, percent in zip(nodes, percents)]
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs