Zusammenfassung der Ressource
Lesson 2: Selection
- Basic ways of controlling order
- Sequence
- Selection
- Iteration
- Boolean operators
- ">" greater than
- ">=" greater than or equal
- "<" less than
- "<=" less than or equal
- "=" equal (in Python this is written as "==")
- "<>" not equal (in Python this is written as "!=")
- Boolean expressions
- A boolean expression evaluates to TRUE or FALSE
- Complex Boolean expressions
- Boolean expressions can include AND, OR and NOT
- AND = Returns TRUE if conditions are true
- OR = Returns TRUE if either of the conditions is true
- NOT = A TRUE expression becomes FALSE and vice versa
- Pseudocode
- Pseudocode is a convient way of writing algorithsms without worrying about the syntax of a particular programming language
- Testing an algorithm
- To make sure your algrotithm works correctly, you should test it with as many sets of test data as needed to make sure it always gives the correct answer
- Writing pseudocode
- Practice: Write pseudocode for a program which asks the user to enter the cost of two items, adds the two costs and if the cost is greater than $10.00, displays a message "Sorry, too much". Otherwise it displays the change due fro $10.00
- Case Statements
- A CASE statement is useful if there are are more than two alternative paths through the program
- Plenary
- IF statements and CASE statements are two different forms of SELECTION statements
- IF statements can be "nested"
- Some languages such as Python do not have a CASE statement
- Pseudocode is a useful tool for developing algorithms before coding them in a programming language
- You should use test data to test that your programs always produce the expected results
- Testing an algorithm
- To make sure your algorithm works correctly, you should test it with as many sets of test data as needed to make sure it always gives the correct answer
- Errors often occurs at "boundaries" - eg.a mark of exactly 50 or 70 should be tested