Shared Flashcard Set

Details

MIT 6.00.1x- Python and CS Basics- Week1
Finger Exercises
104
Computer Science
Undergraduate 1
09/17/2016

Additional Computer Science Flashcards

 


 

Cards

Term
What is the difference between an Algorithm and a Program?
Definition
An algorithm is a conceptual idea, a program is a concrete instantiation of an algorithm.
Term
True or False? A computational mode of thinking means that everything can be viewed as a math problem involving numbers and formulas.
Definition
True
Term
True or False? Computer Science is the study of how to build efficient machines that run programs.
Definition
False
Term
The two things every computer can do are:
Definition
1. Perform calculations
&
2. Remember the results
Term
Declarative knowledge refers to statements of fact.
Definition
True
Term
Imperative knowledge refers to 'how to' methods.
Definition
True
Term
A recipe for deducing the square root involves guessing a starting value for y. Without another recipe to be told how to pick a starting number, the computer cannot generate one on its own.
Definition
True
Term
True or False? A stored program computer is designed to compute precisely one computation, such as a square root, or the trajectory of a missile.
Definition
False
Term
True or False? A fixed program computer is designed to run any computation, by interpreting a sequence of program instructions that are read into it.
Definition
False
Term
A program counter
Definition
points the computer to the next instruction to execute in the program.
Term
What does it mean when we say that "the computer walks through the sequence executing some computation"?
Definition
The computer executes the instructions mostly in a linear sequence, except sometimes it jumps to a different place in the sequence.
Term
True or False? In order to compute everything that is computable, every computer must be able to handle the sixteen most primitive operations.
Definition
False
Term
Syntax
Definition
Determines whether a string is legal
Term
Static semantics
Definition
Determines whether a string has meaning
Term
Semantics
Definition
Assigns a meaning to a legal sentence
Term
3.14
Definition
float
Term
-34
Definition
int
Term
True
Definition
bool
Term
None
Definition
NoneType
Term
3.0
Definition
float
Term
6 + 12 -3
Definition
15
Term
2 * 3.0
Definition
6.0
Term
- - 4
Definition
4
Term
10/3
Definition
3.333
Term
(2 + 3) * 4
Definition
20
Term
2 * 3 * 4
Definition
14
Term
2**3 + 1
Definition
9
Term
2.1 ** 2.0
Definition
4.41
Term
2.2 * 3.0
Definition
6.6
Term
1. What type is returned for the sequentially evaluated problem below
2. What is the value?

a = 3
a + 2.0
Definition
float

5.0
Term
1. What type is returned for the sequentially evaluated problem below
2. What is the value?

a = a + 1.0
a
Definition
float

4.0
Term
1. What type is returned for the sequentially evaluated problem below
2. What is the value?

a = 3
b
Definition
NoneType

error
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

3 > 4
Definition
False
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

4.0 > 3.999
Definition
True
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

4 > 4
Definition
False
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

4 > + 4
Definition
False
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

2 + 2 == 4
Definition
True
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

True or False
Definition
True
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

False or False
Definition
False
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

not False
Definition
True
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

3.0 - 1.0 != 5.0 - 3.0
Definition
False
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

3 > 4 or (2 < 3 and 9 > 10)
Definition
False
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

4 > 5 or 3 < 4 and 9 > 8
Definition
True
Term
Indicate the value returned, or if the evaluation would lead to an error, write the word 'error':

not(4 > 3 and 100 > 6)
Definition
False
Term
Provide the type and the value the expression returns:
a = 3
a == 5.0
a
Definition
int

3
Term
Provide the type and the value the expression returns:
b = 10
c = b > 9
c
Definition
bool

True
Term
Provide the type and the value the expression returns:
3 + 5.0
Definition
float

8.0
Term
Provide the type and the value the expression returns:
5/2
Definition
float

2.5
Term
Provide the type and the value the expression returns:
5/2 == 5/2.0
Definition
bool

True
Term
Provide the type and the value the expression returns:
5/2.0
Definition
float

2.5
Term
Provide the type and the value the expression returns:
round(2.6)
Definition
int

3
Term
Provide the type and the value the expression returns:
int(2.6)
Definition
int

2
Term
Provide the type and the value the expression returns:
2.0 + 5.0
Definition
float

7.0
Term
Provide the type and the value the expression returns:
5*2 == 5.0 * 2.0
Definition
bool

True
Term
Indicate the value returned:
"a" + "bc"
Definition
abc
Term
Indicate the value returned:
3 * "bc"
Definition
bcbcbc
Term
Indicate the value returned:
"3" * "bc"
Definition
error
Term
Indicate the value returned:
"abcd"[2]
Definition
'c'
Term
Indicate the value returned:
"abcd"[0:2]
Definition
'ab'
Term
Indicate the value returned:
"abcd"[:2]
Definition
'ab'
Term
Indicate the value returned:
"abcd"[2:]
Definition
'cd'
Term
1. Evaluate the expression for type
2. and value:
str1
Definition
string

'hello'
Term
1. Evaluate the expression for type
2. and value:
str1[0]
Definition
string

'h'
Term
1. Evaluate the expression for type
2. and value:
str[1]
Definition
string

'e'
Term
1. Evaluate the expression for type
2. and value:
str1[-1]
Definition
string

'o'
Term
1. Evaluate the expression for type
2. and value:
len(str1)
Definition
int

5
Term
1. Evaluate the expression for type
2. and value:
str1[len(str1)]
Definition
NoneType

error
Term
1. Evaluate the expression for type
2. and value:
str1 + str2 + str3
Definition
string

'hello,world'
Term
1. Evaluate the expression for type
2. and value:
str1 + str2 + '' + str3
Definition
string

'hello,world'
Term
1. Evaluate the expression for type
2. and value:
str3 * 3
Definition
string

'worldworldworld'
Term
1. Evaluate the expression for type
2. and value:
'hello' == str1
Definition
boolean

True
Term
1. Evaluate the expression for type
2. and value:
'HELLO' == str1
Definition
boolean

False
Term
1. Evaluate the expression for type
2. and value:
'a' in str3
Definition
boolean

False
Term
1. Evaluate the expression for type
2. and value:
str4 = str1 + str3
'low' in str4
Definition
boolean

True
Term
1. Evaluate the expression for type
2. and value:
str[1:3]
Definition
string
'or'
Term
1. Evaluate the expression for type
2. and value:
str3[:3]
Definition
string

'wor'
Term
1. Evaluate the expression for type
2. and value:
str3[:-1]
Definition
string

'worl'
Term
1. Evaluate the expression for type
2. and value:
str1[1:]
Definition
string

'ello'
Term
1. Evaluate the expression for type
2. and value:
str4[1:9]
Definition
string

'elloworl'
Term
1. Evaluate the expression for type
2. and value:
str4[1:9:2]
Definition
string

'elwr'
Term
1. Evaluate the expression for type
2. and value:
str4[::-1]
Definition
string

"dlrowolleh"
Term
Indicate value printed when expression is evaluated:
if 6 > 7:
print("Yep")
Definition
blank
Term
Indicate value printed when expression is evaluated:
if 6 > 7:
print("Yep")
else:
print("Nope")
Definition
'Nope'
Term
Indicate value printed when expression is evaluated:
var = 'Panda'
if var == "panda":
print("Cute!")
elif var == "Panda":
print("Regal!")
else:
print("Ugly...")
Definition
'Regal!'
Term
Indicate value printed when expression is evaluated:
temp = 120
if temp > 85:
print("Hot")
elif temp > 100:
print("REALLY HOT!")
elif temp > 60:
print("Comfortable")
else:
print("Cold")
Definition
'Hot'
Term
Indicate value printed when expression is evaluated:
temp = 50
if temp > 85:
print("Hot")
elif temp > 100:
print("REALLY HOT!")
elif temp > 60:
print("Comfortable")
else:
print("Cold")
Definition
'Cold'
Term
Write what it prints out, separating what appears on a new line by a comma and a space. If a given loop will not terminate, write the phrase 'infinite loop' (no quotes) in the box.:

num = 0
while num <= 5:
print(num)
num += 1

print("Outside of loop")
print(num)
Definition
0, 1, 2, 3, 4, 5, "Outside of loop", 6
Term
Write what it prints out, separating what appears on a new line by a comma and a space. If a given loop will not terminate, write the phrase 'infinite loop' (no quotes) in the box.:

numberOfLoops = 0
numberOfApples = 2
while numberOfLoops < 10:
numberOfApples *= 2
numberOfApples += numberOfLoops
numberOfLoops -= 1
print("Number of apples: " + str(numberOfApples))
Definition
infinte loop
Term
Write what it prints out, separating what appears on a new line by a comma and a space. If a given loop will not terminate, write the phrase 'infinite loop' (no quotes) in the box.:

num = 10
while num > 3:
num -= 1
print(num)
Definition
9, 8, 7, 6, 5, 4, 3
Term
Write what it prints out, separating what appears on a new line by a comma and a space. If a given loop will not terminate, write the phrase 'infinite loop' (no quotes) in the box.:

num = 10
while True:
if num < 7:
print('Breaking out of loop')
break
print(num)
num -= 1
print('Outside of loop')
Definition
10, 9, 8, 7, 'Breaking out of loop', 'Outside of loop'
Term
Write what it prints out, separating what appears on a new line by a comma and a space. If a given loop will not terminate, write the phrase 'infinite loop' (no quotes) in the box.:

num = 100
while not False:
if num < 0:
break
print('num is: ' + str(num))
Definition
infinite loop
Term
Evaluate what the python program prints:
num = 10
for num in range(5):
print(num)
print(num)
Definition
0, 1, 2, 3, 4, 4
Term
Evaluate what the python program prints:
divisor = 2
for num in range(0, 10, 2):
print(num/divisor)
Definition
0.0, 1.0, 2.0, 3.0, 4.0
Term
Evaluate what the python program prints:
for variable in range(20):
if variable % 4 == 0:
print(variable)
if variable % 16 == 0:
print('Foo!')
Definition
0, 'Foo!', 4, 8, 12, 16, 'Foo!'
Term
Evaluate what the python program prints:
for letter in 'hola':
print(letter)
Definition
'h', 'o', 'l', 'a'
Term
Evaluate what the python program prints:
count = 0
for letter in 'Snow!':
print('Letter # ' + str(count) + ' is ' + str(letter))
count += 1
break
print(count)
Definition
'Letter # 0 is S', 1
Term
For each program, answer the associated questions.
myStr = '6.00x'

for char in myStr:
print(char)

print('done')

Questions:
1. How many times does 6 print out?
2. How many times does . print out?
3. How many times does 0 print out?
4. How many times does x print out?
5. How many times does done print out?
Definition
1. 1
2. 1
3. 2
4. 1
5. 1
Term
For each program, answer the associated questions.

greeting = 'Hello!'
count = 0

for letter in greeting:
count += 1
if count % 2 == 0:
print(letter)
print(letter)

print('done')

Questions:
1. How many times does H print out?
2. How many times does e print out? Disregard the letters in the word done.
3. How many times does l print out?
4. How many times does o print out? Disregard the letters in the word done.
5. How many times does ! print out?
6. How many times does done print out?
Definition
1. 1
2. 2
3. 3
4. 1
5. 2
6. 1
Term
For each program, answer the associated questions.
school = 'Massachusetts Institute of Technology'
numVowels = 0
numCons = 0

for char in school:
if char == 'a' or char == 'e' or char == 'i' \
or char == 'o' or char == 'u':
numVowels += 1
elif char == 'o' or char == 'M':
print(char)
else:
numCons -= 1

print('numVowels is: ' + str(numVowels))
print('numCons is: ' + str(numCons))

Questions:
How many times does o print out? Disregard the o's in last two print statements.
How many times does M print out?
What will the value of the variable numVowels be?
What will the value of the variable numCons be?
Definition
1. 0
2. 1
3. 11
4. -25
Term
Example:
iteration = 0
count = 0
while iteration < 5:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
iteration += 1

Does the following give the same output as the example above (Yes/No)?:

for iteration in range(5):
count = 0
while True:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
Definition
No
Term
Example:
iteration = 0
count = 0
while iteration < 5:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
iteration += 1

Does the following give the same output as the example above (Yes/No)?:

for iteration in range(5):
count = 0
while True:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
break
Definition
No
Term
Example:
iteration = 0
count = 0
while iteration < 5:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
iteration += 1

Does the following give the same output as the example above (Yes/No)?:

count = 0
phrase = "hello, world"
for iteration in range(5):
index = 0
while index < len(phrase):
count += 1
index += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
Definition
Yes
Term
Example:
iteration = 0
count = 0
while iteration < 5:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
iteration += 1

Does the following give the same output as the example above (Yes/No)?:

count = 0
phrase = "hello, world"
for iteration in range(5):
while True:
count += len(phrase)
break
print("Iteration " + str(iteration) + "; count is: " + str(count))
Definition
Yes
Term
Example:
iteration = 0
count = 0
while iteration < 5:
for letter in "hello, world":
count += 1
print("Iteration " + str(iteration) + "; count is: " + str(count))
iteration += 1

Does the following give the same output as the example above (Yes/No)?:

count = 0
phrase = "hello, world"
for iteration in range(5):
count += len(phrase)
print("Iteration " + str(iteration) + "; count is: " + str(count))
Definition
Yes
Supporting users have an ad free experience!