Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Topic 3 – Fact Sheets Pseudocode Pseudocode is a type of simplified code that represents a programming language used to write algorithms (an algorithm is a logical sequence of steps for performing an action). Using pseudocode makes it easier to work out a problem and find solutions before coding is used. Pseudocode does not have a specific syntax and is not a programming language but is a simplified form of code that helps to simplify problems in the planning stages of a program. Pseudocode uses standard tags (called notations) such as: INPUT – user should enter some text (e.g. INPUT "user inputs name") OUTPUT – this indicates something that is output to screen (e.g. OUTPUT "Welcome, Bod!") WHILE – this is used to repeatedly request information until a condition has been met and is referred to as a condition-controlled loop (see Topic 2) FOR – this is used within count-controlled loops and will be repeated subject to the range (see Topic 2) IF, THEN, ELSE – used to test a statement and make a decision If we want to write a program that will ask for the user's name and return a welcome message, the pseudocode may look like this: OUTPUT "Enter your password" INPUT user inputs password STORE password in password variable IF password = "Bod1" THEN OUTPUT "Welcome Bod" ELSE OUTPUT "Incorrect! Please re-enter password to proceed" Conditions – True or False A condition is a statement or calculation which is either true or false. For example, the following statement '1 is greater than 2' is false, whereas the statement '2 is greater than 1' is true. Statements can use operators such as AND, OR and NOT. For example, ‘1 is greater than 2 AND 2 is greater than 1' makes a false statement. The statement '1 is greater than 2 OR 2 is greater than 1' makes a TRUE statement because one of the conditions is true. The NOT operator can be used to refine statements further. For example, 'Chester NOT Liverpool' will find data that matches the Chester criterion and not Liverpool. Expressions In programming there are expressions, operators and conditions. The greater than expression is expressed as the operator > (e.g. 2 > 1). This statement uses a comparison to compare the numbers and makes a decision based on the criteria. As Boolean is based on algebra, numbers can be represented as letters (called variables because the value is subject to change); for example, x > y where x is 2 and y is 1. Boolean operators vary in different languages, such as Python. KS3 Computing Activity Worksheets (Fact Sheets)Page 1 of 3 © ZigZag Education, 2016 Expression Equals Greater than Comparison operator = > Less than < Greater than or equal to >= Less than or equal to Does not equal Expression And Or Not <= <> Boolean operator AND OR NOT Python == != Python and or not Truth Tables and Logic Gates Truth tables help you to see how the input of a logic gate relates to its output using the Boolean operators AND, OR and NOT. Logic gates are switches within circuits which are either TRUE = 1 or FALSE = 0. AND = each input must match criteria OR = one or both inputs must match criteria NOT = output is opposite of input Example of truth table using Boolean operator AND where A AND B equal Z: A 0 1 1 0 B 0 0 1 1 Z 0 0 1 0 Example of truth table using Boolean operator OR where A OR B equal Z: A 0 1 0 1 B 0 0 1 1 Z 0 1 1 1 Example of truth table using Boolean operator NOT where A is NOT equal to Z: A 0 1 Z 1 0 KS3 Computing Activity Worksheets (Fact Sheets)Page 2 of 3 © ZigZag Education, 2016 Examples of logic gates: AND gate: X AND Z must each meet the criteria Y otherwise FALSE (0) X Y Z Look at the example below of a truth table that has been turned into a logic gate where A DOES NOT EQUAL Z A 0 Z 1 NOT gate: Output is opposite of input A Z OR gate: One or both inputs must match criteria A Y Z KS3 Computing Activity Worksheets (Fact Sheets)Page 3 of 3 © ZigZag Education, 2016