NEW
Font size
S
M
L
XL
WorksheetsPlotting in Python
Total questions: 25
Worksheet time: 13mins
Name
Class
Date
1.
What is the name of this famous potential energy function?
a)
Lennard Jones Potential
b)
Lennart Jones Potential
c)
Leonard-Jones Potential
d)
van der Waals Potential
2.
What is the primary challenge in writing pseudocode?
a)
Writing the task without using any functions, sequences, or iteration.
b)
Using proper syntax for every line.
c)
Breaking down a complicated task into smaller, simpler tasks.
d)
Visualizing the internal state of the computer.
3.
Which line contains a syntax error?
a)
G1 = -241.8 - 0.3*188.7
b)
G2 = -285.83 - (0.3*69.9) )
c)
DG = G2 - G1 # kcal/mol
d)
DA = DG - (.018-24.5) / (4184*0.01)
4.
Which of these both produces "ans" and shows it to the user?
a)
1. print(ans)
2. return ans
2. return ans
b)
1. return ans
2. print(ans)
2. print(ans)
c)
1. print(ans)
d)
1. return ans
5.
Which of the following contains a syntax error?
a)
j -= 12
b)
v = arange(100)
c)
y = 4 x**-6
d)
a, b = b-1, a*b
6.
Which is the correct way to define the function "avg"
a)
avg(x) = [...]
b)
def avg(x): [...]
c)
avg = def(x): [...]
d)
def avg x = [...]
7.
Which is the correct for-loop statement?
a)
for x = 1,2,3,4: [...]
b)
for x = [1,2,3,4]: [...]
c)
x for [1,2,3,4]: [...]
d)
for x in [1,2,3,4]: [...]
8.
What is the type of "x" in:
x.append(12)
x.append(12)
a)
list of integers
b)
array of integers
c)
integer
d)
module
9.
What is the type of "x" in:
x[10:20] = exp(x[10:20])
x[10:20] = exp(x[10:20])
a)
list of floats
b)
array of floats
c)
float
d)
module
10.
What types of variables, "x", can be sent to plt.plot(x,y)?
a)
float or array
b)
sequence or string
c)
list or array
d)
numeric
11.
Which of the following contains a syntax error?
a)
'''Queens' College'''
b)
"Queens' College"
c)
'Queens' College'
d)
"""Queens\' College"""
12.
Which is the correct if-statement?
a)
if a and b: [...]
b)
if a and b, [...]
c)
if a and b then: [...]
d)
if a and b then [...]
13.
What is INCORRECT -- about the difference between arange(n) and range(n)
a)
range only works for integer n
b)
range makes a sequence, while arange makes an array
c)
both create sequences
d)
range is numpy-specific
14.
What does the following code produce?
x = zeros((3,5))
x = x.transpose()
x = zeros((3,5))
x = x.transpose()
a)
The tuple, (5,3)
b)
A 3 x 5 matrix of zeros.
c)
A 5 x 3 matrix of zeros.
d)
Undefined behavior.
15.
What does the following code produce?
x = ones((4,5))
y = sum(x,0)
x = ones((4,5))
y = sum(x,0)
a)
A syntax error.
b)
A vector of 4 "4"-s
c)
A vector of 4 "5"-s
d)
A vector of 5 "4"-s
16.
What is the problem here?
def greet(x):
v = x.split()
return "Hello" v[0] v[1]
def greet(x):
v = x.split()
return "Hello" v[0] v[1]
a)
function syntax is bad
b)
return statement needs parentheses ()
c)
split() function is called wrong
d)
no operation connects the names on the last line
17.
What is the specific type of "x" in:
x = [(1,2), (-5,2), (7,8)]
x = [(1,2), (-5,2), (7,8)]
a)
list of objects
b)
sequence
c)
list of tuples of integers
d)
sequence of integers
18.
What is the result of running:
x = [1,2,3]
x.extend(["a", "b", "c"])
x = [1,2,3]
x.extend(["a", "b", "c"])
a)
A list of 6 elements is printed.
b)
The list x is now 6 elements long.
c)
The second line causes a match error.
d)
The mixed types cause an error.
19.
What is returned by:
"to be or not to be".split().count("to")
"to be or not to be".split().count("to")
a)
6
b)
"one two three, hahaha"
c)
[0, 4]
d)
2
20.
Which is the correct list comprehension?
a)
[ z in range(n) ]
b)
[ z for z in range(n) ]
c)
[ for z in range(n): z ]
d)
[ z | z in range(n) ]
21.
Which most strongly indicates that a string is being used?
a)
the function count()
b)
The presence of single or double quotes
c)
the keyword "in"
d)
the slicing syntax, x[3:6]
22.
When is a list comprehension better to use than a numpy array?
a)
When a vector is being computed.
b)
When not working with floats.
c)
When the intermediate result is temporary.
d)
never
23.
Spot the error:
a = "012345"
for i in range(a):
print(i)
a = "012345"
for i in range(a):
print(i)
a)
Print fails since "i" is a string.
b)
Bad for-syntax
c)
range fails since len() is needed
d)
"a" must be a list
24.
What is output by this code:
x,v = 0,1
for i in range(100):
x, v = x+1, v+1
print(x,v)
x,v = 0,1
for i in range(100):
x, v = x+1, v+1
print(x,v)
a)
syntax error in for loop
b)
100,101
c)
0,1
d)
i = 99
25.
If x and c are length 25 vectors, what is the best way to implement the map, x_(n+1) = x_n^2 + c
a)
x, c = x*x, c
b)
x = [x*x + c for x,c in zip(x,c)]
c)
x = x*x + c
d)
for i in range(25):
x[i] = x[i]*x[i]+c[i]
x[i] = x[i]*x[i]+c[i]
Reset
