In: Computer Science
1. What does is mean when a decision structure uses negative logic?
2. Demonstrate how this would be in implemented in a python code snippet (a snippet is just a partial part of the program and not the entire program).
Answer 1:
There are three types of decision logic: straight through logic, positive logic, and negative logic.
Negative logic allows the flow of the processing to continue through the module instead of processing succeeding decisions, once the resultant of a decision is False. Whenever the resultant is False (the Else part of the decision), another decision in the sequence is processed until the resultant is True, or there are no more decisions to process.
Decisions using negative logic use nested If/Then/Else instructions.
Answer 2:
Implementation in a python code snippet:
sales = 10000
if sales>2000:
if sales>4000:
if sales>6000:
commission = 0.1
else:
commission = 0.05
else:
commission = 0.04
else:
commission = 0.03
print(commission)