1/32
Looks like no tags are added yet.
What does = mean in Python?
Assignment: store the right-hand value in the left-hand variable.
What does ** mean?
Exponentiation: 3**2 is 9
How do you write 3 times x?
3*x (multiplication needs *)
How do you write sqrt(x) with NumPy?
np.sqrt(x)
How do you write pi with NumPy?
np.pi (no parentheses)
How do you write e raised to x?
np.exp(x)
How do you write the natural log of x?
np.log(x)
How do you write sin(x) and cos(x)?
np.sin(x) and np.cos(x), with angles in radians
Translate (3 + e^2)/4 into NumPy
(3 + np.exp(2))/4
What does x=4; x=x+3; print(x) output?
7; the previous value of x is increased by 3
Why does calculation order matter?
Python runs assignments in order; a variable must exist before use
What does print("x={}".format(5)) display?
x=5
What does .format(a,b) do with two {} blanks?
Fills them left-to-right with a and b
How do you create a text variable?
Use quotes: title = "AMATH 301".
What is a float versus an integer?
Float is decimal-style numeric; int is a whole-number type
What does 5/2 evaluate to in Python 3?
2.5 (division with / gives a floating-point result)
What is the result of 2*(3+4)?
14; parentheses force 3+4 to happen first.
Write the expression 2^5 + 3 in Python
2**5 + 3
How do you calculate tan(e^2) using NumPy?
np.tan(np.exp(2))
How do you calculate a circle's area if radius=r?
area = np.pi r**2
What will print(type(4)) output?
<class 'int'>
What will print(type(4.0)) output?
<class 'float'>
What does # do in a Python line?
Begins a comment; Python ignores the rest of that line
What does x=3; y=x; x=7; print(y) output?
3; assigning a number to y keeps its current value
What does print('A'+'B') output?
AB; the + joins strings
How do you print 'Area: 12' with .format() when a=12?
print('Area: {}'.format(a))
Why does np.pi() cause an error?
np.pi is a numeric constant, not a function; use np.pi.
What happens if you calculate y=x+1 before defining x?
NameError because x does not yet exist.
How do you calculate the square root of 1+8*e?
np.sqrt(1 + 8*np.exp(1))
What does z=3; z=z**2; print(z) output?
9; the second assignment replaces z with its square.
Does np.log calculate log base 10 or natural log?
Natural logarithm, base e
Which arguments does .format() substitute into '{}' placeholders?
Values passed in order: first {} gets the first argument, etc.