Augustana Computing Science 113 MidTerm Exam
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
Augustana Computing Science 113
MidTerm Exam
2020
Total Marks Available: 60
Calculators and other electronic devices are NOT permitted. This exam must be entirely your own work.
Multiple Choice
Identify the choice that best completes the statement or answers the question. Place your answer on the line beside the question number. Each question is worth 2 marks,for 30 total marks in this section.
__b__
__ __
__b__
__b__
1. What is John von Neumann’s main contribution to computing science?
c. Storing data in memory
d. Inventing Python
2. What is wrong with the following Python statement?
for x in range(0,10)
c. range is not defined
d. A colon is missing
3. Which of the following is a legal variable name in Python?
c. 5things
d. None of the above
4. What is the value of the following Python statement?
25 // 5
c. 5.0
d. 125
__ __
__ __
5. What is the value of the following Python statement?
85 + 2 ** 5 - 3
a. 114
b. 4984209204
6. What is the output of the following Python statements?
x = 10
print (x < 0 or x > 10)
a. False
b. True
__a__ 7. What is the output of the following Python statements?
x = 7
for i in range(10):
print(x, end = '')
a. 7777777777
b. 012345678910
c. 0123456789
d. 77777777777
__b__ 8. Given the following Python statement, what must go in the blank?
for banana in ___________:
a. A range
b. An iterable
c. A mutable
d. A variable
__b__ 9. What is the output of the following Python statements?
for x in range(5,20):
for y in range(8,12,2):
if x < y:
print(x, ' ', end='')
a. 5 6 7 8 9 10 11 c. 5 6 7 6 7 8 7 8 9 10 11
b. 5 5 6 6 7 7 8 9 d. 5 5 6 6 7 7 8 8 9 9
__ __
__ __
10. Which of the following are critical for having or creating an algorithm?
a. Well ordered instructions
b. Doable instructions
11. What should be in the blank of this Python code which is to calculate the number of elements bigger than 10 in myList.
numBig = for x in if x |
0 myList: > 10: |
_____________
c. numBig = numBig + 1
d. numBig = numBig + x
__ __
__b__
__ __
12. What is a pixel?
a. A picture element
b. A cell in the computer’s memory
13. What is the binary number 0111 0001 as a decimal number (base 10)?
a. 112 c. 114
b. 113 d. 115
14. Suppose that x = 'abcdefghijklmnop '. What is the value of x[:-2] in Python?
a. 'abcdefghijklmn' c. 'o '
b. 'op' d. 'nop '
__c__ 15. What is shown after executing the following Python code:
import turtle
s=turtle.Screen()
t=turtle.Turtle()
for i in range(8):
t.forward(100)
t.right(45)
t.hideturtle()
.
.
.
.
Longer Answer
Answer thefollowing questions completely and succinctly. Show all work.
16. Given the following Python code, describe the execution including diagrams to show how the computer’s memory will look and change. [15 marks]
1. def pete(aNum):
2. x = -1
3. pal = 1 4.
5. while pal <= aNum:
6. pal = pal * 2
7. x = x + 1
8.
9. return x
10.
11. x = 40
12. print(pete(40))
11 In memory the variable x is assigned the value 40.
Memory
12 Need to print the value of pete(40) so control transfers to 1. We will come back here when we find a return or the function ends.
1 Set up memory with aNum
Memory
|
2 pete’s x is initialized
3 pete’s pal is initialized
Memory
|
5 The condition evaluates to True (1 < 40), so the loop body will execute
6 The value of pal doubles, is now 2
7 pete’s x increases by 1, is now 0. That is the end of the loop body so go to beginning of loop
5 The condition evaluates to True (2 < 40), so the loop body will execute
6 The value of pal doubles, is now 4
7 pete’s x increases by 1, is now 1. That is the end of the loop body so go to beginning of loop
5 The condition evaluates to True (4 < 40), so the loop body will execute
6 The value of pal doubles, is now 8
7 pete’s x increases by 1, is now 2. That is the end of the loop body so go to beginning of loop
5 The condition evaluates to True (8 < 40), so the loop body will execute
6 The value of pal doubles, is now 16
7 pete’s x increases by 1, is now 3. That is the end of the loop body so go to beginning of loop
5 The condition evaluates to True (16 < 40), so the loop body will execute
6 The value of pal doubles, is now 32
7 pete’s x increases by 1, is now 4. That is the end of the loop body so go to beginning of loop
5 The condition evaluates to True (32 < 40), so the loop body will execute
6 The value of pal doubles, is now 64
7 pete’s x increases by 1, is now 5. That is the end of the loop body so go to beginning of loop
Memory
|
|
||||
|
40 |
||||
|
|
|
|||
|
|||||
|
|||||
|
5 The condition evaluates to False (64 < 40), so the loop body will NOT execute
9 Go back to the print instruction (12) and take the value of pete’s x, which is 5
12 continued. Display (print out) 5 to the console. Lost pete’s variables on return.
Memory
17. Write a Python program to find the median of three numbers given by a user. For example, ifthe user enters 14, 17 and 2 then the median should be 14. Include documentation. [15 marks]
2022-04-09