Section 1 Chapter 1 - Programming Basics Flashcards
What is an algorithm
A sequence of steps that can be followed to complete a task and that always terminates
What is pseudocode
A tool for developing programs which is halfway between English and program statements. There are no concrete rules or syntax for how it is to be written
Integer
A whole number
Real / Float
A number with a fractional part
Boolean
A variable that can be either true or false
Character
A letter, number or special character typically represented with ASCII
String
A sequence of characters
Syntax to round n
round(n, decimalPlaces)
Syntax for exponentiation
a**b
Syntax for integer division
a div b
Syntax for modulo
a mod b
Syntax for finding length of string
len(string)
Syntax for getting the index of a substring in a string
string.find(substring)
Syntax for getting the integer (ASCII) value of a character
ord(char)
Syntax for getting the character represented by an integer
chr(integer)
Syntax for converting a string to an integer
int(string)
Syntax for converting an integer to a string
str(integer)
Syntax for converting a string to a float
float(string)
Characteristics of the bullshit returned by date(year, month, day)
Is a number but also a date >:(
(Assumptions)
When made via the date function and then printed it is so in the format “year-month-day”
When two dates are subtracted from each other the result is an integer representing the number of days difference between them
What actually are variables
Identifiers given to memory locations whose contents can change over the course of the program
Constant
An identifier given to a memory location whose contents cannot change over the course of the program
Advantage of using constants
In a lengthy program there is no chance that they can be accidentally changed
Why meaningful variable names should be used
Makes the program easier to update and follow
Data Type
The ‘type’ of a piece of data describes how it is meant to be handled and what operations are valid/invalid for it,