/******************************************************************/

This document is subject to change.  Please monitor (refresh/reload) regularly.

Please report any errors or omissions in this document: 
anne.dawson@gmail.com

This document is current at: Tuesday 30th October 2018, 7:07 PT, AD

REFRESH/RELOAD THIS PAGE OFTEN FOR LATEST VERSION

/******************************************************************/

CSCI120 QUIZ 3
==============


EXAM CONDITIONS APPLY FOR ALL QUIZZES
ELECTRONIC EQUIPMENT SHOULD BE SWITCHED OFF 
AND PLACED AT THE FRONT OF THE ROOM.

Exam Rules
Academic Honesty Policy
Notes on Academic Honesty (Thanks to Greg Baker, SFU)
Example of Academic Honesty Violation


Quiz 3 covers ***all*** topics covered in the course
up to and including OOP.

*** The focus of Quiz 3 is strings, files, searching and OOP ***


Note: Students may be tested in a quiz or an exam
on the content of reading assignments and lab assignments.

 
All the topics are listed on the course schedule for the current semester.


CSCI120 QUIZZES
===============

There are three quizzes worth 20% in total:
Quiz 1 = 6%
Quiz 2 = 6%
Quiz 3 = 8%

The lowest scoring quiz will be dropped at the end of the course
so that the remaining 2 quizzes are worth 10% each.

The date of the quiz is shown in the course schedule and on C4.
See C4 for the latest details about Quiz 3.
  

Note: Students may be tested in a quiz or an exam
on the content of reading assignments and lab assignments.


The format of Quiz 3 is as follows:



Quiz 3
======

(8% of final grade, 60 minutes)


Questions are based on the course notes and assignments.

Quiz 3 is closed-book: no books, notes, calculators, phones
or any other electronic equipment are allowed during quizzes.

Questions types may include (in any combination): multiple choice, short answer, 
written questions, questions requiring interpretation of Python 3 code, 
detection of errors and writing new Python 3 code.





Quiz 3 covers all topics covered in the course. 

*** The focus of Quiz 3 is strings, files, searching and OOP ***

All the topics are listed on the course schedule for the current semester.




Example Quiz 3 questions:


1. Which of the following code fragments is correct?
A) print("Score : " + 91)
B) print("Score : " + int(91))
C) print("Score : " + str(91)
D) print("Score : " + str(91))

Answer: D



2. An escape sequence is used in programming languages 
such as Python to designate a nonprintable character 
such as a newline or a tab. 
Which of the following characters starts an escape sequence?
A) e
B) %
C) \
D) #

Answer: C



3. Which of the following is an escape character?
A) n
B) 'n'
C) '\n'
D) "n"

Answer: C



4. Which of the following is an escape character?
A) 't'
B) 'n'
C) '\t'
D) "n"

Answer: C



5. Which one of the following 
can be used as a string formatting code 
for printing an integer within a string?
A) %c
B) %d
C) %f
D) %s

Answer B




6. In Python programs, to output a floating point number 
of any size to two decimal places, 
you would use which of the following string format codes?
A) %0.2f
B) %02f
C) .2%f
D) %2.0f

Answer: A



7. A string can span multiple lines 
if it is enclosed within which of the following?
A) '
B) "
C) '''
D) ''''

Answer C



8. In Python, 
you cannot concatenate a string and an integer; 
you must convert the integer to a string first.
A) True
B) False

Answer: A



9. If  x is a string variable, which of the following Python statements is legal?
A) x * 3
B) x - 1
C) x / 2
D) x + 2
E) All of the above are illegal statements

Answer: A



10. Place these five software lifecycle phases into the correct order (performed first to last):
algorithm design, coding, maintenance, problem definition, testing

Answer: problem definition, algorithm design, coding, testing, maintenance



11. Python strings are mutable.  True or False?
A) True
B) False

Answer: B


12. What, if anything, 
is wrong with the following Python statement 
which is intended to open file 
C:\temp\file1.txt for reading?

file1 = open('C:\\temp\\file1.txt','r')
A) The file path should be enclosed in double quote marks.
B) There should be a single \ where there are two.
C) The text 'r' should be replaced with 'w'.
D) There is nothing wrong.

Answer: D



13. Predict the output:

f = open("test.dat","w") 
f.write("Today is Saturday\nand the sun shines\nand I walk the dog\n") 
f.close() 
f = open("test.dat","r") 
str1 = f.readline()
str1 = f.readline()
str2 = str1 + f.read(4)
print (str2)


Answer:

and the sun shines
and 


14. (written Question)
Compare and contrast 
the sequential search algorithm 
with the binary search algorithm

Answer: see notes on the topic of Searching


15.  _______ is a template, blueprint,
or contract that defines objects of the same type. 
 A. A class
 B. An object
 C. A method
 D. A data field

Answer: A



16. An object is an instance of a __________.
 A. program
 B. class
 C. method
 D. data

Answer: B



17.  The ________ creates an object in the memory and invokes __________.
 A. the __init__ method 
 B. the init method
 C. the initialize method
 D. the __str__ method

Answer: A



18. Analyze the following code:

 class A:
     def __init__(self, s):
         self.s = s
 
     def print(self):
         print(s)

 a = A("Welcome")
 a.print()

 A. The program has an error because class A does not have a constructor.
 B. The program has an error because class A should have a print method with signature print(self, s).
 C. The program has an error because class A should have a print method with signature print(s).
 D. The program would run if you change print(s) to print(self.s).

Answer: D




GPA
===
Your attendance, conduct and progress are monitored throughout the course.
You may inspect your status report at any time using the online Gradebook. 
Your login details for the online Gradebook 
are attached to your marked and returned Quiz 1 paper. 
Should you lose your login details, 
see the instructor in any Office Hour.

The date of the quiz is shown in the course schedule - latest details on C4.

/************************************************************/
Good Luck!
AD
/************************************************************/
 

End of document

 

 


 




































Valid HTML5!

Valid CSS!