1/36
carleton
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
modulus (remainder)
% a%b= a-a/ / b*b
int division
// (rounds to the lowest int value)
variable
stores value and name
x = 2 # 1
y = x # 2
y = x == 2 # 3
y = (x = 2) #4
y = (x == 2) #5
which of the statements contains a SyntaxError?
4
Write a code fragment that sets a variable test to True when the float variable x is equal to 0.0 +/- 0.001
Check all that apply.
1 | test=x<=0.001 and x>=-0.001 |
2 | test=x>=-0.001 or x<=0.001 |
3 | test=(x>=-0.001) and (x<=0.001) |
4 | test=abs(x) <= 0.001 |
5 | test = x == 0 |
1
3
4
x = (1/3) == 0.3333
what is x
False (It is inadvisable to compare floating point numbers for equality using ==.
Instead floating point numbers are generally compared to be equal within a window of precision)
What decimal value does the 8-bit word 010000112 represent, if the word is interpreted as a signed magnitude number?
67
when converting decimal to binary, when given 1 / 2 it equals 1 NOT 0. but then will give you 0 / 2 which is also 1
wipefhipWGHwehfpwewf
how to convert decimal to binary fraction (ex. 0.625)
times by 2, and do it to a diff decimal place each time (first number will be 1 or 0)
What is the most appropriate precondition that should be included in the docstring for this function:
def slope(x1, x2, y1, y2):return (y2 - y1) / (x2 - x1)
| |
| |
| |
No precondition is needed. |
Precondition: x2 != x1
By annotating parameter x, as float. what type of values can x be in a function?
int or float
def add_one(x):x = x + 1return xx = 0
y = add_one(3)print('x = ', x, 'y = ', y)
How many function calls are in the code?
2
def plus_two(x):return x + 2
which of the following code fragments contain valid calls to the function? Select all correct choices.
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
1, 3, 5, 6
After this code is executed, what value does x refer to?
def func1(x):x = 4 * x
x = 0
x = func1(10)
0 | |
10 | |
40 | |
None |
none, (Functions without a return statement in their body return None)
def add_one(x):x = x + 1return xx = 0
y = add_one(3)
How many variables named x and y appear in the memory model just before the return statement is executed?
two x's and one y | |
two x's | |
one x and one y | |
one x |
2 x’s
How do we indicate the end of a block of statements in Python?
Ensure that the statement that follows the block is "undented"; that is, its indentation is less than the indentation of the last statement in the block.
What is printed by the following code snippet?
x = 4y = 3if x == 3:print(1)print(2)if y == 3:print(3)print(4)
NOTHING (if isnt right spacing)
|
|
|
Parameter
The header and body of a function.
Function definition
An expression whose value is passed to a function.
Argument
in a function call, arguments appear between
parentheses
The first line of a function definition is called the
header
parameter is the
variable
the value of the parameter is the
argument
What do while-loops do
Repeat a chunk of code until a condition is false but will excute the code the first time the condition is false (live and learn)
number = 5
while number >= 0:
number -= 1
print (number)
4
3
2
1
0
-1
(forces it to print since the code has already in excuted???)
number = 5
while number >= 0:
print (number)
number -= 1
4 3 2 1 0 (number it printed before thing so it already realizes that its false???) |
what is range when there is 3 variable
(start, stop, step) (whatever the last number is doesnt count, ex , (1, 2,5) would just have 1)
does range work for floats
NO only ints
what for loop do
variable is assigned for elements in a sequence(repeats sqeunce fixed amount of times, need to know how many times code need to be iterated)
for num in range(6):
print (num, end=" ")
print("")
0 1 2 3 4 5 (end=" “ tells python not to go to next line, and instead but space)
how to call function from file import function
from (file) import (function)
just use function name (ex. from f_mod.py import f(). call = f() )
how to call function by import file
import (file)
just put file name (without .py) and function name
(ex. import f_mod. call = f_mod.f() )
What is the difference between executing a module vs. importing a module?
The variable "__name__" changes value inside the module
When designing test cases, it is important to ensure full "coverage". What does this mean?
Your test cases should include extreme values (min, max of expected range) for arguments | |
Include at least one test case for each type of behaviour for the function | |
Make sure every logical path through your code is executed by the test cases |
what are examples of iterable data
lists and strings