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('{0} {1}'.format(f(a), f(b)))
def f(x):
# your solution here
run()
The following program is intended to deposit $100 into an empty
account and display the resulting balance, so it should display
100.0.
Explain why it displays 0.0
instead.
def deposit(account_balance, deposit_amount):
account_balance = account_balance + deposit_amount
my_account = 0.00
deposit(my_account, 100.00)
print(my_account)
What does the below program display?
def go(x):
y = step(x)
z = step(y)
print('{0} {1} {2}'.format(x, y, z))
def step(a):
a = a + 1
return a + 1
go(5)
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('{0} {1}'.format(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('{0} {1}'.format(a[0], b[0]))
def add_lists(x, y):
x = [x[0] + 20]
y[0] = x[0] + y[0]
run()
What is displayed when the below program is executed?
def run():
a = 1
y = 2
b = process(a)
c = process(b)
print('{0} {1} {2}'.format(a, b, c))
print(y)
def process(x):
y = x + 1
x = x * 2
print(y)
return x
run()
Perform each of the following conversions.
a. | 1101(2) | to decimal |
b. | 100110(2) | to decimal |
c. | 22(10) | to binary |
Perform each of the following conversions.
a. | 100101(2) to decimal |
b. | 53(10) to binary |
a. | 101101(2) | to decimal |
b. | 1010101(2) | to decimal |
c. | 23(10) | to binary |
d. | 95(10) | to binary |
Explain what ASCII is and what ASCII's purpose is.
Identify three categories of characters that are defined in Unicode but not in ASCII.
def f(x):
if x == 16.0:
return 4.0
else:
return 7.0
Two shorter alternative bodies for f
:
or
return x ** 0.5
return (x + 28) / 11
At the time of the function call, my_account
's value is copied
into the deposit
function's account_balance
variable;
but the call does not establish any link between the variables
beyond simply copying the values at this time.
Thus, when deposit
later changes the value
associated with account_balance
, this does not affect
the value associated with my_account
, and so
my_account
remains unchanged from its initial value of 0.
11 11 4
3 9 3 10
6 7 16 17 8 3
10 70
2 3 1 2 4 2
8 bits × 1,024 bytes = 8,192 bytes byte KB KB
a. | 1101(2) = | 13(10) |
b. | 100110(2) = | 38(10) |
c. | 22(10) = | 10110(2) |
a. | 100101(2) is 37(10) |
b. | 53(10) to binary is 110101(2) |
a. | 101101(2) | is 45(10) |
b. | 1010101(2) | is 85(10) |
c. | 23(10) | is 10111(2) |
d. | 95(10) | is 1011111(2) |
ASCII is a mapping between distinct seven-bit values and the characters found on an American keyboard (plus some additional non-printable symbols). This is used for encoding text in files and in network communications.
There are many answers here, but some possibilities: accented characters for other European languages (like ñ, é, and ö), Chinese characters (Han alphabet), the Cherokee alphabet, the Greek alphabet, the Arabic alphabet, the Hebrew alphabet, Egyptian hieroglyphics, playing cards, emoticons, mathematical symbols, and musical notes and symbols.