Python代写-MTH 280
时间:2022-05-05
Final Exam — MTH 280
Name:
Code on the written portion uses Python 3, which is the version of Python we have been using throughout this course.
I. WRITTEN
Rules: Open book. You can use the internet, notes, or anything else besides other people.
1. For each of the following vocabulary terms, write a concise 1-2 sentence definition or description. Be brief, and
to the point.
• (2 points) Python list
• (2 points) Local variable scope
• (2 points) Boolean expression
2. (3 points) List 3 limitations of the floating-point number system (as compared to the real number system).
3. (2 point) Your friend claims they wrote a program to compute an integral with relative errors smaller than
10−32. Do you believe them? Why or Why not?
24. (.5 points per answer = 1 point per row) Pretend you are the Python interpreter. Evaluate each of the expres-
sions below. Write down the value that they evaluate to, and the type of that value in the provided columns.
If the expression is not valid python syntax, or will result in an error, simply write “Error”. If there is no
associated type write “NA”. The first line has been provided as an example.
Expression Result Type
1 + 2*3 7 int
2 == 3
list(range(2)) + [“M83”]
np.array( [3.14, 15] )
[1,2,3][“start”]
[1,2,3,4][1:]
abs([-3.0])
17 = x
[2*i for i in [0,1]]
[1,2,3][-2]
35. (4 points) Pretend you run the following program on the terminal (or in spyder). Write down exactly what the
output would be.
1 def mysteryFun1(x):
2 print("I love "+x)
3 return("waffles")
4 print("pancakes")
5
6 mystery = mysteryFun1("fruit")
7 print("I ate")
8 print(mystery)
Output:
46. (4 points) Pretend you run the following program on the terminal (or in spyder). Write down exactly what the
output would be.
1 def mystery_function(n):
2 if n <= 1:
3 return 1
4 answer = 0
5 for i in range(n):
6 answer = answer + i
7 return answer
8
9 print( mystery_function(1) )
10 print( mystery_function(3) )
Output:
57. (4 points) Pretend you run the following program on the terminal (or in spyder). Write down exactly what the
output would be.
1 myList = [4, 6]
2 x = sum(myList)
3
4 if x/10 == 1:
5 print("a")
6 myList = [1, 1, 1]
7 else:
8 print("b")
9 myList = [3, 4]
10
11 ### x = 100
12
13 if x <= 25:
14 print( len(myList) )
15 elif x <= 20:
16 print( sum(myList) )
17 else:
18 print( myList )
Output:
68. (4 points) Pretend you run the following program on the terminal (or in spyder). Write down exactly what the
output would be.
1 def modify_list(myList,i):
2 temp1 = myList[i]
3 temp2 = myList[i+1]
4 myList[i] = temp2
5 myList[i+1] = temp1
6 return myList
7
8 grades = [100, 7]
9
10 num_grades = len(grades)
11
12 print("Number = %i"%num_grades)
13 print(grades)
14
15 grades = modify_list(grades,0)
16
17 print(grades)
Output:
9. (4 points) The following code has an error. Describe the problem and the fix.
1 from sin import math
2 x = sin(1.0)
3 x = x * 3
4 print( x )
10. (4 points) The following code has an error. Circle the line and explain whats wrong.
1 g = 10
2
3 def ball():
4 g = 9.8
5 y = 0.5*g*t**2
6 return y
7
8 y = ball(1.0)
9 print(y)
10 print(g)
11. (4 points) The following code has an error. Circle the line and explain whats wrong.
71 x = 100
2
3 if x < 10:
4 print("x is small")
5 else:
6 print("x is medium")
7 elif x > 200:
8 print("x is large")
9
10 def square_me(y):
11 return y*y
12
13 print( square_me(x) )


essay、essay代写