Unit 7 Flashcards
(42 cards)
What is a data type
The kind of values that can be used in a data item
How do you define a constant in OCR exam reference language and why do we do it
you write “const” first then define the variable
ie: “const MIN_AGE = 7”
they are typically shown in uppercase
It prevents the code from accidentally being changed by another part of the code
It shows a programmer that the value should stay the same
Can a constant ever change its value
The value of a constant variable cannot be changed when a program is running
The value of a constant can be changed by a programmer before it is compiled/translated
What is casting
When you use a function to change the data type of a variable
What does bool(x), ASC(x) and CHR(97) do
1) converts x into a boolean (eg: “True” into True)
2) converts whatever the character(s) is into ASCII (ie: a would become 97)
3) converts the ascii back to regular character(s) so 97 would be “a”
What is concatenation
Joining together multiple items of the same data type (ie: string)
what does the .substring(x,y) function do to a string
it takes a string (ie: London Zoo) and it takes the x position and finds that character, the y position on the string and finds that character and then prints everything in the middle of those
ie: substring(1,4) will take the first “o” and the 2nd “o” (the 1st and 4th position) and it will use everything in between (including this) so the result will be “ondo”
What does .left(x) ad .right(x) do
.left(x) will take the first x characters out of a string and print them. Opposite for .right() - if the last 4 characters are “goat” from “gogoat” then instead of printing taog it will print goat as its in order
What are the purpose of comments
Describing the purpose of an algorithm
State the author of the program
Explain what the code does
What are the boolean operators
AND
OR
NOT
When do you use the switch case statement
When a selection is to be made from several alternatives (ie: choosing from a menu)
What does the library function round() do
if the statement is round(x, n) then the function rounds a real (x) to n decimal places
How do you use random number generation for python and pseudocode
Pseudocode:
die = random(1, 6)
print(die)
Python:
import random
die = random.randint(1, 6)
print(die)
for randomising, all numbers including start and end are inclusive for both languages
what is the definition of sequence
the statements are executed one by one in the order they are written
selection
The next statement to be expected depends on whether the condition tested is true or false
iteration
Repetition of a section of code
Describe a for loop
Its a fixed loop - the code is repeated a known number of times
When a fixed loop executes, the program counts the number of ties the code has been repeated which is stored in the loop variable
How can you work out how many times a for loop will run if you’re given the loop ie: for counter = 0 to 9 and what about python
the last number - the first + 1 // the step
9-0+1 = 10
if its from 1 to 9 then it will be 9 times
For python it is just the last - the first as it is exclusive
(THIS WORKS FOR POSITIVE AND SOME NEGATIVES I THINK)
What is an array
A data structure allowing you to several variables of the same type with one name
How do you define an array of constants
name = [“…”, “…”, “…“…]
It doesn’t have to be only string
What is an advantage of using arrays
Instead of making a bunch of different variables, you can make one array to store all of the different values, which can be individually accessed easily otherwise it would be very inconvenient
How do you construct a 2D array in pseudocode
Student1 1 2 3 4
Student2 4 5 5 1
student3 9 8 9 9
array Total[3]
What’s the difference between a function call and function definition
definition: used to define the steps within the function
call: Tells the program to branch to the function, execute it and comeback to the next statement in the program
What’s the difference between a function and procedure
FUNCTION RETURNS A VALUE
PROCEDURE DOES NOT