Perform each of the following conversions.
| a. | 100101(2) to decimal |
| b. | 53(10) to binary |
| c. | the eight-bit two's-complement pattern 11100110 to decimal |
| d. | the number −23(10) to an eight-bit two's-complement pattern |
Convert the below to an equivalent if statement where
not doesn't appear.
if not (a == b or a.getX() > b.getX()):
What is displayed when the below program is executed?
def run():
a = 3
x = 4
weird(a)
weird(a)
print x
def weird(y):
x = y * 2
y = x + 5
print y
run()
What is displayed when the below program is executed?
def run():
x = 3
y = weird(x)
print x, y
def weird(z):
print z
z = z * z
print z
return z + 1
run()
What is displayed when the below program is executed?
def run():
a = 3
print f(a)
print a
def f(x):
print g(x)
a = x + 5
print g(a)
return a
def g(y):
y = y * 2
print y
return y + 1
run()
What is displayed when the below program is executed?
def run():
a = [10]
b = [40]
add_lists(a, b)
print a[0], b[0]
def add_lists(x, y):
x = [x[0] + 20]
y[0] = x[0] + y[0]
run()
Complete the f function below so the below program, when
executed, displays 4.0 7.0
. (Do not modify anything
except the body of f. There are many possible answers.)
def run():
a = 16.0
b = 49.0
print f(a), f(b)
def f(x):
run()
Complete the below function so that given a list of integers, it returns the number of them that are even.
def count_evens(numbers):
| a. | 85(10) |
| b. | −86(10) |
| c. | 00011010 |
| d. | 10011000 |
| a. | 100101(2) is 37(10) |
| b. | 53(10) to binary is 110101(2) |
| c. | the eight-bit two's-complement pattern 11100110 is −26(10) |
| d. | −23(10) is represented as 11101001 |
if a != b and a.getX() <= b.getX():
11 11 4
3 9 3 10
6 7 16 17 8 3
10 70
def f(x):
if x == 16.0:
return 4.0
else:
return 7.0
Two shorter alternative bodies for f:
or
return x ** 0.5return (x + 28) / 11
count = 0
for num in numbers:
if num % 2 == 0:
count = count + 1
return count