Programming Flashcards
What is a data type?
Specification is what type of value a variable has.
What are the five data types?
Integer
Real/float
Character
String
Boolean
What is an integer?
A numerical data type for whole numbers
2/4 bytes
What is a real/float ?
A numerical data type for decimal numbers
4/8 bytes
What is a character?
A single alphanumerical symbol
1 byte
What is a string?
A data type for one or more alphanumerical characters.
* can be a number or string
1 byte for each character
What is a Boolean?
A data type that can only take one of two values - TRUE or FALSE
1 bit-1 byte
What is the difference between constants and variables?
Variables can be changed throughout out the program.
What is iteration?
Loops controlled by conditions
What are types of indefinite iteration?
Only rely on a condition(can be infinite):
Repeat until- condition at end, run at least once
While- condition at the start of loop
Do while
What is selection?
Causes the program to make a choice and flow in a given direction
What is a variable?
A named piece of memory that holds a value , can change as the program is running
What is a constant?
A named piece of memory where the value cannot be changed while a program runs
What is a type of selection?
An if else statement
What is definite iteration?
A loop that repeats a set number of times - usually a for loop
What is a nested statement ?
An iteration or selection made up of multiple statements inside each other
What is the need for meaningful identifiers?
Suitable names for variables, makes it easier for the next person to work on the code to understand
How do you find the length of a string?
LEN(string)
*starts from 1
🐍len(string)
How do you find the position of a string?
POSITION(string,character)
*includes the 0
🐍 string.index(‘x’)
How do you take a certain part of the string?
SUBSTRING(x ,y ,string)
*includes the 0
*does include last number
🐍string[x : y]
*does not include last number
How do you concatenate strings?
+
Does not include spaces
Normally done with variables
🐍everything has to be a string
How do you change one data type to another?
STRING_TO_INT (“your mom”)
STRING_TO_REAL (“your mom “)
INT_TO_STRING (69)
REAL_TO_STRING (9.58)
🐍
str()
int()
float()
How do you get the quotient (whole number)?
DIV
🐍//
How do you get the remainder?
MOD
🐍%