Core Elements of Programs Flashcards

1
Q

What are the types of programming language?

A

Compiled (High level language)
Instructions are converted to low level ahead of time

Interpreted (Low level language)
Instructions are processed on the fly at the basic level of the computer

Interpreted (High Level language)
Instructions are processed on the fly at a high level which enables more abstract computation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a program?

A

A program/script is a sequence of definitions and commands. It manipulates data objects.
Definitions are evaluated.
Commands are are executed by the shell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a shell?

A

Provides access to operating system services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a command?

A

A command/statement instructs the interpreter to do something.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the types of data objects?

A

Scalar: int (5, 47)
float (4.7, 3.14)
bool (True, False)
NoneType

Non-scalar:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an expression?

A

Composed of operators and data objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What arithmetic operators are used on ints and floats?

A
i+j -  Sum
i-j  -  Difference
i*j  -  Multiplication
i/j - Division
i//j  -  Division (int)
i%j -  Remainder
i**j -  Power
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What comparison operators are used on ints and floats?

A

i>j - Greater than
i>=j - Greater than or equal to
i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What logic operators are used on bools?

A

a and b - True if both are True
a or b - True if either are True
not a - True if a is False, False if a is True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are type conversions?

A
float(3) = 3.0
int(3.4) = 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you bind values to variables and names?

A

=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is operator overloading?

A

Using the same operator to achieve different things based on the type of object.

Depending on the type of the object, number or string the operator will decide what the right operation is to do.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is string indexing vs slicing?

A

Indexing selects an individual letter from a string of characters

Slicing selects a portion of a string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you index an individual character from a string?

A

‘abc’[2]&raquo_space;> ‘c’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you slice a set of characters from a string?

A

‘Python’[1:5]&raquo_space;> ‘ytho’

‘Python’[0:0:2]&raquo_space;> ‘Pto’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you denote a comment in a script?

A

#

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How do you prompt for user input?

A

name = raw_input(‘Enter your name:’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the syntax for nested conditionals?

A

if - checks a specific value
elif - checks a specific value if not already found
else - default if no criteria are met

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How do you get the remainder from numbers?

A

%

20
Q

How do you print a calculation externally without the value being used for computation?

A

print(

i.e: print(5+3)

21
Q

What are the arguments for string slicing?

A

‘string’[start:stop:step]

22
Q

When changing the value of an object that is bound to a value what is important to consider?

A

Changing that value will not effect any other objects that previously used the object

23
Q

When using strings why use “ or ‘?

A

“is used if the string contain’s an apostrophe”

24
Q

What is the syntax for a while loop?

A

while

25
Q

What does a += b stand for?

A

a = a + b

26
Q

What does a -= b stand for?

A

a = a - b

27
Q

What does a*= b stand for?

A

a = a * b

28
Q

What does a /= b stand for?

A

a = a / b

29
Q

What is the equivalent to a = a + b?

A

a += b

30
Q

What is the equivalent to a = a - b?

A

a -= b

31
Q

What is the equivalent to a = a * b?

A

a *= b

32
Q

What is the equivalent to a = a / b?

A

a /= b

33
Q

What is the syntax to stop a loop executing?

A

break

34
Q

When putting a conditional piece of syntax what do you need to remember?

A

Close it with a :
if ans = 0:
while ans <= 5:

35
Q

How do you find the absolute value of a number?

A

abs(

36
Q

How do you get a sequence of integers

A
range(n) = [0, 1, 2, 3, ..., n-1]
range(m,n) = [m, m+1, ..., n-1]
37
Q

What is the while loop?

A

Repeats a statement while a given condition is true
Unbounded number of iterations

while x < 5:

38
Q

What is the for loop?

A

Repeats a statement a given number of times

for i in range(4):
for i in s: #Reference string directly

39
Q

What are the arguments for range?

A

range(start,stop,step)

40
Q

What are the ways of concatenating strings?

A
print("I am", x, "years old")
#Used to concatonate int variables directly
print("I am " + str(x) + " years old
#Can only concatenate string type variables
41
Q

What is an immutable object?

A

Its value cannot change
s[0] = “b” #Error because strings are immutable
s = “b” + s[1:] #Must rebind s

42
Q

How do you assign expressions(code) to conditionals?

A

Indentation

43
Q

When using input, what type variable is stored?

A

String

44
Q

What parameters constitute an object?

A

Identity
Type
Value

45
Q

What is lexicographic order?

A

Alphabetic order, is inherently known in python for strings