Variables, Constants, Operators, Inputs, Outputs, Assignments
Folien in diesem Satz (6)
-
- A variable is a memory location holding a data item which may change value during a program execution.
- Variables may be integer, real/float, character, string, boolean.
- Variable names can be a mixture of letters and numbers, but should start with a letter. It is the value of the variable that can change during execution, not the name.
- Using a related name to what the variable is will help reduce errors as if you don't use a related name then you're more likely to get confused.
- The scope of a variable (local or global) tells you which parts of the program the variable can be used in.
- The identifier is the name which refers to the memory location where the data item is stored.
-
- Local variables are recognised only in their subroutine and if you try to use them in the main program, you will get an error message.
- Variables declared inside a sub program. This means they're invisible to the rest of the program and can't be used outside of the sub program.
- They can't affect and aren't affected by anything outside of their subprogr
- The scope of a global variable is the whole program, including their subroutines.
- They're defined by global: global y = 0
-
- Some programming languages allow the use of constants. The value of a constant cannot change during the execution of the program.
- Constants are assigned a data value at design time.
- Constants are assigned using the const command - const distance = 40
- They're declared at the start of the program.
- When its value changes you only have to change it in one place rather than looking throughout the whole program for everywhere that value was used.
-
- An input is what gets entered by the user.
- When an input is needed, the user will typically be prompted to type something and this gets assigned to a variable.
- For example: name=str(input("Enter your name: ")) - This means that the variable name is assigned whatever the user inputs.
- Inputs can be checked using input validation which is where data is checked to see whether it meets a certain criteria before passing it into the program. Examples include:
- Range check - Checks to see whether the data is within a specified range Presence check - Checks the data has actually been entered Format check - Checks the data is in the correct format Look up table - Checks the data against a table of acceptable values Length check - Checks the data is the correct length
- Output is the end result after the data has been processed. This could be a printed report, a value, a graphic on a screen etc.
- The print statement is used to output data to the screen.
- For example: print("Your name is", name) - This would print "Your name is" followed by whatever was stored under "name".
-
- Variables are assigned using the = sign.
- x = 1
- pi = 3.14
- street = "Elm street"
- letter = "a"
- over18 = True
-
Operators (Arithmetic and Comparison)
- Arithmetic operators take two values and perform a maths function on them. These operators work on floats or integers.
- Addition +
- Subtraction -
- Multiplication *
- Division /
- Modulus (prints remainder of division) MOD or % 20%8 = 4
- Integer division (prints how many times the number can go into the other one without a remainder) DIV or // 20//2 = 8
- Exponent (to the power of) ** 2**3 = 2^3 = 8
- Can evaluate to true or false.
- Equal to ==
- Not equal to !=
- Less than <
- Less than or equal to <=
- Greater than >
- Greater than or equal to >=
Informationen
- Beschreibung
- GCSE Computer Studies Folienset am Variables, Constants, Operators, Inputs, Outputs, Assignments, erstellt von Izzy DB am 17/12/2021.
- Erstellt von
- Izzy DB
- Aufrufe
- 5
- Bewertung