Keywords Input Output Assignment Pseudocode Flowchart Identifier Variable

Keywords Input, Output, Assignment, Pseudocode, Flowchart, Identifier, Variable, Constant Concatenation, Memory locations, Parameters Variables Inputs, Outputs and Assignment

What is a variable? Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. Computer programs accept inputs from a user, processes them using some constants and outputs back to the user. It is a good idea to label various inputs, constants and outputs with descriptive names (the process known as assignment). None of them should start with a number or contain spaces. INPUT Name Phrase = “I like you ”+ Name OUTPUT Phrase What is assignment? During assignment, information is stored in memory locations under descriptive names called “identifiers”. A memory location where information relevant to the program running is stored is called: - “a variable” if it changes throughout the program or - “a constant” if it is fixed for the duration of the program.

BIG PICTURE Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. Variables are like building blocks or containers from which we build up our programs. Like blocks in Tetris, variables come in different types, like different containers for different purposes in real life: - a milk jug looks different from a petrol can - liquids are stored differently from solids.

Memory Locations Objectives Any information that a program makes use of, e. g. user's age, is stored in RAM while the program runs. RAM is divided in memory locations with long hexadecimal (but really binary) addresses. BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. Here, we use Python to find out the addresses hiding behind the labels "a" and "b" that we gave them to store values 6 and 8, respectively.

Coding vs Spreadsheets Objectives We have renamed our variables from the spreadsheet style to the one more common on programming. BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. Why did we rename A 1 and B 1 to first_num and second_num?

Pseudocode vs Flowcharts Objectives BEGINNER: Explain input, assignment and outputs within programming. START SPACE = “ “ INPUT Name ADVANCED: Identify variables and constants in programs. Phrase = “Hello” + SPACE + Name OUTPUT Phrase EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. END

Constants Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. In the previous program one of the labels (SPACE) was in capital letters. This refers to memory locations that hold CONSTANT values. Constants are values that don’t change as the program runs. Here is another well-known constant:

Output Objectives BEGINNER: Explain input, assignment and outputs within programming. Computers are general-purpose problem solving machines. Just like most machines, they need raw materials, known as inputs, time and instructions to process the inputs the results, known as outputs. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. Example of output: A program stores a message that it wants to display to user.

Inputs Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. Without inputs, our programs are not very useful as they can’t interact with the outside world and always produce the same result. We are going to create a program that asks user to input their name and then greets them by concatenating (joining) their name with a greeting. Inputs come from the console, from a file, or from elsewhere in a modular program – are known as “parameters”.

Inputs and assignments Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. In most programming languages, inputs come as text. “ 1234” is still text, until you need to use it in calculation – at which point it needs to be converted to a number. Once the data is input into the program, we often need to store it. We store data by “assigning” it to a memory location with a descriptive label, known as a “variable”. OUTPUT “Try again” NO YES EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. INPUT User. Name INCREMENT attempts User. Name recognized? INPUT Pwd

Problem Solving Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. In Physics, we can look at an object falling from rest. The formula for its velocity after a time of t seconds is v = g * t where g is the acceleration of gravity. The value for g on planet Earth is 9. 8 m/s 2. A. What is the velocity of a tennis ball after 5 seconds of falling?

Variables and Constants Objectives BEGINNER: Explain input, assignment and outputs within programming. ADVANCED: Identify variables and constants in programs. EXPERT: Develop programs to solve problems that use constants, variables, inputs, assignment and outputs. In the example program we used capital letter G for gravity acceleration. We use CAPITAL letters for CONSTANTS – values that don’t change between the program runs (they remain, “constant”). Marking constants in capitals simplifies debugging (constants are less likely to generate mistakes as they don’t change during runtime) and is good industry practice. VARIABLE CONSTANT
- Slides: 12