Bug Hunt
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Consider the following code, which is designed to convert a temperature in degrees Celsius to a temperate in degrees Fahrenheit and print the result:
# Inputs:
celsius = 27
print(celisus * 1.8 + 32)
celsius, even if that value is changed. Are there any bugs in the code? If so, briefly explain them:
Formatting Help
Consider the following code, which is designed to calculate the amount in a bank account with an annual interest rate r (compounded annually) after n years, with an initial investment of d dollars, and print the result:
# Inputs:
r = .06 # interest rate
d = 100 # current number of dollars in the bank account
n = 20 # years
# calculate the amount of dollars after adding interest
(d * (1+r)**n)
print(d)
r, d, and n, even if those values are changed. Are there any bugs in the code? If so, briefly explain them:
Formatting Help
Consider the following code, which is designed "clip" a value x to be between two limiting values, lo and hi
It should print:
- the value of
xifxis betweenloandhi, - the value of
loifxis less thanlo, or - the value of
hiifxis greater thanhi
The code is as follows:
# Inputs:
x = 20
lo = 6
hi = 9
if x < lo:
print(lo)
if x > hi:
print(hi)
else:
print(x)
x, lo, and hi, even if those values change. Are there any bugs in the code above? If so, briefly explain them:
Formatting Help
6.s090