Evaluating process: Difference between revisions
Mr. MacKenty (talk | contribs) |
Mr. MacKenty (talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
You should remember your order of operations: | You should remember your order of operations: | ||
In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.<ref>https://en.wikipedia.org/wiki/Order_of_operations</ref> The mathematical order of operation is: PEMDAS ( | In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.<ref>https://en.wikipedia.org/wiki/Order_of_operations</ref> The mathematical order of operation is: PEMDAS (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction). | ||
== How to evaluate a process == | == How to evaluate a process == | ||
Line 15: | Line 15: | ||
=== Example === | === Example === | ||
Imagine you are writing a simple computer program which must output the winner of a game. A winner is determined | Imagine you are writing a simple computer program which must output the winner of a game. A winner is determined by the highest numerical score (int). The input is two scores. The output must be only one of the scores below: | ||
# The first score is the winner | # The first score is the winner | ||
Line 24: | Line 24: | ||
def whoIsTheWinner(score1, score2): | def whoIsTheWinner(score1, score2): | ||
if | if score1 > score2: | ||
winner = "The first score is the winner" | winner = "The first score is the winner" | ||
elif | elif score2 > score1: | ||
winner = "The second score is the winner" | winner = "The second score is the winner" | ||
else: | else: | ||
winner = "There is a tie" | winner = "There is a tie" | ||
return winner | |||
</syntaxhighlight> | </syntaxhighlight> | ||
If we were to evaluate this process, we would | If we were to evaluate this process, we would stop at '''each line of execution''' the value of each variable (score1 and score2). We would then ask ourselves: | ||
# If score1 is higher than score2, would the program output score1 is the winner? | # If score1 is higher than score2, would the program output score1 is the winner? | ||
Line 38: | Line 39: | ||
# If both scores are the same, would the program output there is a tie? | # If both scores are the same, would the program output there is a tie? | ||
Other Questions to code: | |||
# If John is a bachelor, then he is male. John is male. Therefore, John is a bachelor. | |||
# If today is Monday, then I will attend cooking class today. | |||
# Either the current pope is married or he is a divorcé. | |||
== Standards == | == Standards == |
Latest revision as of 18:11, 2 September 2018
You must evaluate if the sequence of activities (or instructions) will result in the required outcomes. This evaluation can be logical, arithmetic, or both.
A common scenario is evaluating the order of conditionals. You must become very good at tracing conditional expressions.
You should remember your order of operations:
In mathematics and computer programming, the order of operations (or operator precedence) is a collection of rules that reflect conventions about which procedures to perform first in order to evaluate a given mathematical expression.[2] The mathematical order of operation is: PEMDAS (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction).
How to evaluate a process[edit]
Use a step-by-step process and trace the value of a variable or value. Ask yourself, at each step in the process, what is the current value or state of a variable. Let's look at some examples.
Example[edit]
Imagine you are writing a simple computer program which must output the winner of a game. A winner is determined by the highest numerical score (int). The input is two scores. The output must be only one of the scores below:
- The first score is the winner
- The second score is the winner
- There is a tie
def whoIsTheWinner(score1, score2):
if score1 > score2:
winner = "The first score is the winner"
elif score2 > score1:
winner = "The second score is the winner"
else:
winner = "There is a tie"
return winner
If we were to evaluate this process, we would stop at each line of execution the value of each variable (score1 and score2). We would then ask ourselves:
- If score1 is higher than score2, would the program output score1 is the winner?
- If score2 is higher than score1, would the program output score2 is the winner?
- If both scores are the same, would the program output there is a tie?
Other Questions to code:
- If John is a bachelor, then he is male. John is male. Therefore, John is a bachelor.
- If today is Monday, then I will attend cooking class today.
- Either the current pope is married or he is a divorcé.
Standards[edit]
- Evaluate whether the order in which activities are undertaken will result in the required outcome.