• No results found

The total points for the exam is 150 points

N/A
N/A
Protected

Academic year: 2021

Share "The total points for the exam is 150 points"

Copied!
10
0
0

Loading.... (view fulltext now)

Full text

(1)

Name:

Section: Date:

INSTRUCTIONS:

(1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

(2) This exam booklet contains 30 questions, each of which will be weighted equally at 5 points each. The total points for the exam is 150 points.

(3) You may use one 8.5” x 11” note sheet during the exam. No other reference materials or electronic devices may be used during the examination, i.e. no cal- culators, cell phones, mp3 players, etc. Paper dictionaries are allowed.

(4) Questions will not be interpreted during the examination.

(5) You should choose the single best alternative for each question, even if you believe that a question is ambiguous or contains a typographical error. If a question has more than one best answer, credit will be given for any of the correct answers.

Provide only one answer.

(6) Please fill in the requested information at the top of this exam booklet.

(7) Use a #2 pencil to encode answers on the OMR form.

(8) Please encode the following on the OMR form:

– Last name and first initial – MSU PID

– Exam form (1 A)

(9) Please sign the OMR form.

(10) Only answers recorded on your OMR form will be counted for credit. Completely erase any responses on the OMR form that you wish to delete.

(11) You must turn in this exam booklet, the OMR form, your note sheet, and your scrap paper when you have completed the exam. Be sure your name is on any of these items that you would like to have returned.

(12) The exam ends at 2:00 pm. When leaving, please be courteous to those still taking the exam.

(2)

Form A

1 2 3 4 5 6 7 8 9 10

C D A C C B D B A ABCDE

11 12 13 14 15 16 17 18 19 20

B A D A C B C D D CD

21 22 23 24 25 26 27 28 29 30

AE C D D A C B A B C

Questions 10, 20, and 21 had typographical errors.

The error in question 10 was announced during the exam. Students were told to mark any answer to that question to receive full credit for the question.

The missing colon in the figure for questions 20 and 21 make the correct answer for those questions D and E, respectively. But because many students did not notice the missing colon and it was an unintended error, we gave full credit for the answer that would have been correct if the colon had not been omitted.

The answers marked above are the ”best answers”. Partial credit was given for some answers that were ”almost” correct.

(3)

(1) Which of the following statements is correct?

(a) Evaluation of a Python expression may not produce a side effect.

(b) A Python expression cannot be a variable.

(c) Evaluation of a Python expression returns a value.

(d) All of (a)–(c).

(e) None of (a)–(c).

(2) If ERR MSG and PROMPT reference string values, which of the following produces a side effect?

(a) print(ERR_MSG) (b) ans = input(PROMPT) (c) PROMPT = "What number?" (d) All of (a)–(c)

(e) None of (a)–(c)

(3) Which of the following is not allowable syntax in Python?

(a) print(x += 1) (b) __bye_str

(c) len = 5 (d) "*|" * 35 + "*"

(e) None of the above (all are allowable).

(4) After the assignments x = 5 and y = 3.5, what is returned by evaluation of y ** x >= y * x != x + y?

(a) An error. (b) False (c) True

(d) None of (a)–(c)

(5) After the assignments x = 5 and y = 3.5, what is returned by evaluation of y / (x - 5) < 0 and x ** 2 == 25?

(a) True (b) False (c) An error.

(d) None of (a)–(c)

(6) After the assignments x = 5 and y = 3.5, what is returned by evaluation of x ** 2 == 25 or y / (x - 5) < 0?

(a) False (b) True (c) An error.

(d) None of (a)–(c)

(7) If the value associated with variable n is a non-negative integer, which expression returns the digit in the tens-place of the value’s decimal representation (e.g., returns 6, if the value of n is 365)?

(a) n % 10 % 10 (b) n // 10 // 10

(c) n % 10 // 10 (d) n // 10 % 10

(e) None of (a)–(d)

(4)

(8) After the assignments s1 = "536" and s2 = "55", what is returned by s1 > s2?

(a) True (b) False (c) An error.

(d) None of (a)–(c)

(9) After the assignments s1 = "536" and s2 = "55", what is returned by float(s1) > int(s2)?

(a) True (b) False (c) An error.

(d) None of (a)–(c)

(10) After the assignments s1 = "Scoo" and s2 = "bee" and s2 = "doo", what is returned by s1 <= s1 + s2 <= s1 + s3?

(a) An error. (b) False (c) True

(d) None of (a)–(c)

x = int(input("Enter an integer: ")) if x <= 30:

print(1) elif x > 150:

print(2) elif x < 0:

print(3) else:

print(4)

Figure 1

(11) In Figure 1, what will be printed if the user enters 300 at the prompt?

(a) 1 (b) 2 (c) 3

(d) 4 (e) None of (a)–(d)

(12) In Figure 1, what will be printed if the user enters 30 at the prompt?

(a) 1 (b) 2 (c) 3

(d) 4 (e) None of (a)–(d)

(13) In Figure 1, what will be printed if the user enters 50 at the prompt?

(a) 1 (b) 2 (c) 3

(d) 4 (e) None of (a)–(d)

(14) In Figure 1, what will be printed if the user enters -10 at the prompt?

(a) 1 (b) 2 (c) 3

(d) 4 (e) None of (a)–(d)

(5)

n = input("What integer? ") while False: # Line 1

n = input("Try again:") print(n)

Figure 2

(15) In Figure 2, what is printed if the user enters 1.5 at the prompt?

(a) Try again: (b) 1 (c) 1.5

(d) An error. (e) None of (a)–(d)

(16) In Figure 2, what replacement for the condition False in Line 1 will cause the program to keep prompting for an integer until the user enters one, and then print the integer entered?

(a) not n.isdigit() and n[0] != "-" or not n[1:].isdigit() (b) not n.isdigit() and (n[0] != "-" or not n[1:].isdigit())

(c) n.isdigit() or n[0] == "-" and n[1:].isdigit()

(d) not n.isdigit() and not n[0] != "-" or n[1:].isdigit() (e) None of (a)–(d)

(17) What is printed by: print(str(ord("9") - ord("3")))

(a) six (b) "6" (c) 6

(d) An error. (e) None of (a)–(d)

(18) What is printed by: print(str(ord("9" - "3")))

(a) 6 (b) "6" (c) six

(d) An error. (e) None of (a)–(d)

(19) What is printed by: print(chr(ord("a") + 5))

(a) An error. (b) e (c) abcde

(d) f (e) None of (a)–(d)

(6)

num = int(input("Enter a positive integer: ")) r = num

f = 2 w = ""

while r > 1:

if r % f == 0

w += str(f) + " "

r = r // f else:

f = f + 1

print(w) # Line 1

print(f, r) # Line 2

Figure 3

(20) In Figure 3, what is printed by Line 1 if the user enters 12 at the prompt?

(a) 2 3 4 6 (b) 2 3 (c) 2 2 3

(d) An error (e) None of (a)–(d)

(21) In Figure 3, what is printed by Line 2 if the user enters 12 at the prompt?

(a) 3 1 (b) 4 1 (c) 3 0

(d) 4 0 (e) None of (a)–(d)

(22) What is returned by "({:<6.2f}-{:4s}-{:4d})".format(5//4, str(1.5), 13) (a) "(1.25 - 1.5- 13)" (b) "( 1.25-1.5000- 13)"

(c) "(1.00 -1.5 - 13)" (d) "( 1.25-1.5 - 13)"

(e) None of (a)–(d)

(23) What is returned by len("{:4},{:4},{:4}".format(’a’, ’b’, ’c’))?

(a) 3 (b) 5 (c) 12

(d) 14 (e) None of (a)–(d)

(7)

saying = "The holy grail."

print(saying[5] + saying[-5]) # Line 1

print(saying[4:-4]) # Line 2

i = 0

for c in " .,?":

saying = saying.replace(c,"") i = i + 1

print(i) # Line 3

print(saying.lower()) # Line 4 saying = saying[saying.find("h"): \

saying.find("y")][::-1]

print(saying) # Line 5

Figure 4

(24) In Figure 4, what is printed by Line 1?

(a) h r (b) hr (c) o r

(d) or (e) None of (a)–(d)

(25) In Figure 4, what is printed by Line 2?

(a) holy gr (b) holy gra (c) oly gra

(d) h o (e) None of (a)–(d)

(26) In Figure 4, what is printed by Line 3?

(a) 0 (b) 3 (c) 4

(d) 5 (e) None of (a)–(d)

(27) In Figure 4, what is printed by Line 4?

(a) theholy grail (b) theholygrail (c) Theholygrail (d) theholygrail. (e) None of (a)–(d)

(28) In Figure 4, what is printed by Line 5?

(a) loheh (b) ylohe (c) theholygrai

(d) theholygrail (e) None of (a)–(d)

(8)

def f(s,n):

for i in range(len(s)-1):

if s[0] < s[len(s)-1]:

s = s[1:]

continue n += 1

s = s[1:]

return n g = "spartan"

m = 3 r = f(g,m)

print(r) # Line 1

print(m, g) # Line 2

Figure 5 (29) In Figure 5, what is printed by Line 1?

(a) 9 (b) 7 (c) 3

(d) 0 (e) None of (a)–(d)

(30) In Figure 5, what is printed by Line 2?

(a) 9 spartan (b) 7 n (c) 3 spartan

(d) 9 n (e) None of (a)–(d)

(9)
(10)

Scratch

References

Related documents

The house, built in 1911, is an early Vancouver home, valued for its association with the growth and development of the Cedar Cottage neighbourhood, once part of the

Main exclusion criteria were: botulinum toxin injections in the past 6 months, nerve stimulation therapy for OAB treatment except for successful PTNS treatment, obvious

When an auditor is unable to inspect and count a clients investment securities until after the balance sheet date, the bank where the securities are held in a safe-deposit box

Consequently, the objective of this study was to test the agronomic performance of a group of commonly grown cereal crops including maize, sorghum, pearl and finger

Interviews were conducted before and after intervention using a physical restraint questionnaire to examine any change in staff knowledge, attitudes, and behaviours on physical

For dry soils, apply 1/4 to 1/2 inch of water the day before a treatment to improve spray pene- tration of the soil and to encour- age white grubs to move closer to the soil

Over the past nearly two decades, Nutrasource has expanded its services far beyond its original omega-3 blood test to include international regulatory capabilities,

From the Active Directory Services window that appears, select the Identity Management for UNIX checkbox.. Click OK to close the Active Directory Services window and then click Next