6.00.1x & 6.00.2x Flashcards Preview

Python/Java & Computer Science > 6.00.1x & 6.00.2x > Flashcards

Flashcards in 6.00.1x & 6.00.2x Deck (71)
Loading flashcards...
1
Q

imperative vs. declarative knowledge

A

declarative - statement of facts

imperative - recipe or “how-to” computation

2
Q

What is the difference between a program and a algorithm?

A

An algorithm is a conceptual idea, a program is a concrete instantiation (representation?) of an algorithm.

3
Q

A computational mode of thinking means that everything can be viewed as a math problem involving numbers and formulas.

True or False ?

A

True

4
Q

Computer Science is the study how to build efficient machines that run programs.

True or False ?

A

False

5
Q

What does it mean when we say that “the computer walks through the sequence executing some computation”?

A

The computer executes the instructions mostly in a linear sequence, except sometimes it jumps to a different place in the sequence.

6
Q

What are primitive operations and what are some examples of primitive operations ?

Where are they in a computional machine?

A

A low-level object or operation from which higher-level, more complex objects and operations can be constructed.

Examples: addition, subtraction, examine true or false statements

In the ALU - arithmetic logic unit

7
Q

What “Determines whether a string is legal”?

A

syntax

8
Q

What “determines whether a string as meaning”?

A

semantic syntax

9
Q

What “assigns a meaning to a legal sentence”?

A

semantics

10
Q

What is the output after each expression ?

Remember this is one session - each expression is calculated directly after the previous problem.

A
  1. 5.0 and float
  2. 4.0 and float
  3. none type and error
11
Q

What sort of expression is this ?

and what value is returned ?

A

Bool

True

12
Q

print(ss[-4:-1])

How do you read slicing strings with negative index numbers ?

A

Same as positive

Read from left to right

remember starting value is inclusive

ending value is exclusive

13
Q

What is the significance of the stride in slicing ?

A

it allows you to choose the interval at which python takes parts when slicing

14
Q

How do you print in reverse order using slicing ?

A

Double colon to signify that this applies to the whole string

and then have -1 as the stride value.

15
Q

What is the return value of this piece of code ?

and why?

A

Hot

because the computer reads the code in a linar fashion and the value meets the if statement to ‘print’ HOT.

16
Q

What does += mean?

A

add whatever number to the varaible that is attached to it

mysum += i

17
Q

What is a recipe?

A
  1. Sequence of simple steps
  2. Flow of control process that specifies when each step is executed
  3. A means of determining when to stop
18
Q

How many primitives do you need to do any calculation

A

6

19
Q

What are expressions ?

A

complex but legal combinations of primiives in a programming language

20
Q

What could go wrong when writing a program ?

A

Syntactic errors

Static syntactic errors

No semantic error but different meaning to what the programmer intended

21
Q

The difference between static semantics and semantics?

A

A statement in python may have meaning (it is statically semantically correct), but it may not do what you intended (it is not semantically correct).

22
Q

List all the operations on ints and floats

A
23
Q

How do you bind a value to a variable ?

A

Using the equals sign

e.g. pi = 3.14159

24
Q

What are the comparison operators for Ints and Floats ?

A
25
Q

Why is an indentation important?

A

Each indented set of expressions denotes a block of instructions.

Indentations also provide a visual structure that reflects the semantic structure of the program.

26
Q

What is a Branching program ?

A

The simplest branching statement is a conditional

A test ( an expression that evaluates to true or false )

A block of code to execute if the test is true

An optional block of code to execute if the test is false

27
Q

What is a nested conditional?

A

That inside a block, you have another conditional

28
Q

What does ‘control flow - branching’ do?

A

evaluates expressions in blocks if <condition> is <strong>True</strong></condition>

29
Q

For logical operator OR, what do you need to have a True output?

A

You need one True part of the statement

30
Q

True or False

Output ?

A

True

31
Q

BINDINGS: What would be the final answer ?

A

First as you go through the code you see that y is being assigned the value of ‘x’, which is 1.

So the new value of y is 1.

Now assigning the value of y to x, we know that y is 1 so the final value for x is 1

32
Q

STRINGS: How do you concatenate two strings with a space?

A

you have to add (with plus signs) to double quotation marks

33
Q

STRINGS: How do you find the length of string ?

What about spaces?

A

len( )

includes spaces

34
Q

STRINGS: If you index ‘eric’ with [1:3]

what is the output ?

A

The first element which is r

and the second element i

it doesn’t include the third element as you might think

In ranges like these when indexing you include the starting index element but the finishing index value is not included

Final output: ‘ri’

35
Q

STRINGS: what does the -1 mean for this string slicing?

A

a negative number means you count from the end of the array instead of the beginning.

36
Q

STRINGS: What result would this slicing have?

A

Every element except for the last one.

37
Q

STRINGS: What about this entail?

A

it would reverse the order of the string

38
Q

STRINGS: What would this return?

A

Nothing because it can’t step back any places when it is confined between 0 and 9.

You cannot start at 0 and count backwards to 9…

39
Q

STRINGS: How do you convert an integer into a string?

A

str(x)

where x is a variable holding the value

40
Q

INPUT/OUTPUT: Why were the quotation marks also printed?

How do end up with an int for the output value?

A

Because input simply expects everything to be a string.

Whatever I type it is going to read it in as a string.

Even if you inputted a number it is going to interpret it as a string of the characters of the number.

So you need to turn it into an int before you actually use it.

41
Q

INPUT/OUPUT: What is the ouput? And Why ?

A

The output is Hot

Code is ran linearly, from top to bottom, and it sees the “Hot” if statement first, and will never get to the “really Hot” elif statement because it already exited the loop at the first if.

42
Q

IDE: What is an IDE ?

A

Integrated development environment

43
Q

What do for and while loops do?

A

they can create an infinitely long looping of an expression(s) until it is stopped.

44
Q

Difference between for and while ?

A

for has a function integrated into it that allows you to define a range

45
Q

if you find this expression ..

mysum += i

i being a variable

what should think of ?

A

that some value is being added to mysum - mysum accumulates thes sums…

46
Q

Summarize for and while loops main features.

A
47
Q

When would you use a for loop?

And similarly, when would you use a for loop?

A

Use a for loop when you know what you are going to do as a computation

use a while loop when there is a condition that you can’t predict that would allow you to break out of the loop.

48
Q

EX vara varb: How could you have made the code shorter ?

A

instead of using ‘if’ clauses throughout you could have used ‘elif’ clauses after the first ‘if’ statement and that will have stopped you from having to test for ‘integers’ - the elif statement is only read if the first condition isn’t met. So if the condition is true it will have stopped there.

49
Q

Inside if statements that are inside ‘for’ and ‘while’ loops, if there is a break, what happens?

A

it stops the whole loop ( for or while )

50
Q

What do you need to remember about division in python?!

A

It always returns a float!

51
Q

What’s the answer to this question?

Why is it the way it is?

A

This is the answer as the code clearly states that after the count increase by 1 the loop should be broken…That means that no more iterations of the loop are going to take place, so the only printed value will be for the first letter ‘S’,

52
Q

Are space taken into account for a string in a for loop function!

A

yes !

spaces are also considered characters in python

53
Q

GUESS & CHECK: What is the output of an input function?

A

a string

54
Q

If you can remember, how did this work?

A

It worked because index was reset every time, due to the index = 0 variable. You can do this when the variable definition is inside the loop.

55
Q

What sort of input does the input function expect?

A

It expects a string.

So if you write something with double quotes attached, it will print the double quotes.

56
Q

How do you convert the input function from string to int?

A

write int() around the input function.

57
Q

What does the range option entail in a for loop?

A

Specifies what value you want the for loop to go to.

58
Q

how do you define a stop and step when using range

A

range(start, stop, step)

59
Q

what is important to remember about the stop value when using range?

A

the stop is actually equal to stop - 1

60
Q

What does this output ?

A

0.0, 1.0, 2.0, 3.0, 4.0

When you divide there the output is a float…

61
Q

What did you learn about the alphabet in python ?

A

that python recognizes alphabetical order, so you can simply test individual letters to see if one is higher up on the alphabet.

62
Q

What does an immutable type mean ?

A

You can’t change them.

They can’t be modified.

63
Q

How could you change a string?

A

You can’t change the string individually, you have to redefine the variable it is in.

64
Q

What does int(4.7) become in python?

A

4

Python simply truncates down.

65
Q

When slicing, is the final number inclusive or not?

A

Not inclusive, so if the range is 1:4, 4 is not included.

66
Q

How can you skip characters while slicing?

A

you add a third element to the slicing,

example

1:6:2

67
Q

What type does ‘input’ always use?

A

string

you need to enclose by int() if you want an integer.

68
Q

What is the order of growth of this function?

What did you learn?

A

The order of growth is O(log(b)).

Why? Well if you put in some testing values for b, like 16, you’ll notice that it takes 4 steps to get to b = 1, which can be represented by log2 (16). The last step from 1 to 0 can be ignored because as b gets larger so does that step become more negligible. Similarly, if b is odd, there is one extra step that becomes negligible for large values of b.

The best way to approach these problems is to write down the general step equation for the whole function and then identify the dominant factor from there.

69
Q

Why is the big O of this function log(b)?

A

By converting the number into a string it is iterating over the characters of the string and not through the length of the number. For example, 110 is broken up as ‘1’, ‘1’ and ‘0’ as a string while as a number the for loop would go through every value until 110. By converting it into a string the function essentially divided by 10 on each iteration.

So the number of iterations through the loop can be seen as log(b).

You should remember this next time you see an integer being converted into a string, even though it probably isn’t the most effective method.

70
Q

If a recursive function calls the function twice in the return, what sort of complexity is it?

A

exponential

71
Q
A