Sale!

ECE-203 Laboratory Experiment Week 3 solution

$30.00

ECE-203 Programming for Engineers
Laboratory Experiment Week 3
Name:
In Lab Assignments (Due end of this lab session)
(10 Points) Let p be a bank’s interest rate in percent per year (APR). An initial amount of money
M will mature to the amount of
M
(
1 +
p
100
)n
after n years have passed. Write a Python program that computes how much $1,000 will have
matured to after 5 years with an interest rate of 0.95% APR1

Category:

Description

5/5 - (1 vote)

ECE-203 Programming for Engineers
Laboratory Experiment Week 3
Name:
In Lab Assignments (Due end of this lab session)
(10 Points) Let p be a bank’s interest rate in percent per year (APR). An initial amount of money
M will mature to the amount of
M
(
1 +
p
100
)n
after n years have passed. Write a Python program that computes how much $1,000 will have
matured to after 5 years with an interest rate of 0.95% APR1
.
TA Initials
(10 Points) Type up and run this short program intended to evaluate the expression
y = sin2
(x) + cos2
(x)
from math import sin, cos, pi
x = pi/4
1_val = sin^2(x) + cox^2(x)
print 1_VAL
Fix this program by identifying and correcting erroneous statements, syntax errors, etc.
TA Initials
(10 Points) The following code attempts to solve the constant acceleration example we discussed
in the second lecture
v0 = 3 m/s
t = 1 s
a = 2 m/s**2
d = v0*t + 1/2 a*t**2
print d
Again, fix this program by identifying and correcting erroneous statements, syntax errors, etc.
TA Initials
1Look online – is this a good interest rate for a savings account in the current market?
1
(10 Points) The following code attempts to verify the equations
(a + b)
2 = a
2 + 2ab + b
2
(a − b)
2 = a
2 − 2ab + b
2
a = 3,3 b = 5,3
a2 = a**2
b2 = b**2
eq1_sum = a2 + 2ab + b2
eq2_sum = a2 – 2ab + b2
eq1_pow = (a + b)**2
eq22pow = (a – b)**2
print ’1st equation: %g = %g’, % (eq1_sum, eq1_pow)
print ’2nd equation: %h = %h’, % (eq2_pow, eq2_pow)
Again, fix this program by identifying and correcting erroneous statements, syntax errors, etc.
TA Initials
(10 Points) Given the quadratic equation
ax2 + bx + c = 0
the two roots are
x1 =
−b +

b
2 − 4ac
2a
, x2 =
−b −

b
2 − 4ac
2a
.
Identify the problem with the following program.
import math
a = 7
b = 26
c = 3
q = math.sqrt(b*b – 4*a*c)
x1 = (-b + q)/2a
x2 = (-b – q)/2a
print “””
x1 = %g
x2 = %g
“”” % (x1, x2)
TA Initials
2