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

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: Monday 9th July 2018, 11:51 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. 
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, exam or assessed lab
on the content of reading assignments, 
in-class assignments and homework assignments.




The format of Quiz 3 is as follows:



Quiz 3
======

(8% of final grade, 70 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. 
All the topics are listed on the course schedule for the current semester.




Example Quiz 3 questions:



1.  What is the output of this Python 3 program?

x = 17 / 2 % 2 * 3**3
print (x)

A. 13.5
B. 16 
C. 54.0
D. none of the others



Answer: A. 13.5

For an explanation of the example question above,
see Example 5 in the following document:
Operator Precedence 





 
2.  The following program will create the output shown beneath it.

Program:

print (7 > 10)
print (4 < 16) 
print (4 == 4) 
print (4 <= 4)  
print (4 != 4)  

Output: 

False
True
True
True
False

A. True
B. False



Answer: A. True






3.  What is the output of this Python program?


num1 = 5
if num1 >= 91:
    num2 = 3
else:
    if num1 < 6:
        num2 = 4
    else:
        num2 = 2
x = num2 * num1 + 1
print (x,x%7)



A.  21    3 
B.  21    0
C.  21    21
D.  none of the others



Answer B. 21   0







4. The three types of error that might be contained in a Python program are syntax, logic and run-time.

A. True
B. False


Answer: A. True






5. What is an algorithm?

A. a keyword of the Python language
B. a Python built-in function
C. a Boolean operator
D. a written description of the steps to solve a problem


Answer: D.  a written description of the steps to solve a problem.







6. A computer program is the implementation of an algorithm.

A. True
B. False


Answer: A. True





7. What is the data type of a value such as 3.142?


A. float
B. string
C. int
D. Boolean



Answer: A.  float





8. What is the data type of a value such as 3?

A. float
B. string
C. int
D. Boolean



Answer: C.  int









9. What is the data type of a value such as "anne was here"?

A. float
B. string
C. int
D. Boolean



Answer: B.  string









10.  What is the output when the following code is executed?

list1 = [2,4,6,8,10,12,14,16,18,20] 
print (list1[0:1],list1[5:7])

Answer:

A.  [2,4] [10, 12]
B.  [2,4] [12, 14]
C.  [2] [12, 14]
D.  [2] [10, 12, 14]




Answer: C.  [2] [12, 14]





11. (Short answer) Write the truth table for the not Boolean operator.

Answer:

value of A       not A
false            true
true             false




12. (Short answer) List four advantages of using functions in a program.

Answer:

divides the work into teams
makes software development more manageable
enables software reuse
avoids repetition
makes programs more understandable
easier to debug
easier to maintain
easier to test







13. (Short answer) The range built-in (always available) function has this syntax:

range([start,] stop [,step])

Explain this syntax.

Answer: 

The stop argument is required, the others are optional. 
Repeats to one minus the stop value, in steps of one, unless other step value specifed.







14. (Short answer)  Write two lines of Python 3 code that prints "error!" forever when run.

Answer: 

while 1:
	print ("error!")







15. (Short answer)  Give an example of a run-time error.

Answer:

attempt to divide by zero 







16. (Short answer)  Give an example of a syntax error.

Answer:

attempt to divide by a string object  






17. (Programming Question)

a) 7% Define a function (the function definition only) named combine_lists that receives two lists of integers (the function has 2 parameters). You can assume that each list is the same length and each list is not empty. The function will create a new list which is composed of the addition of each element of the two lists. The function returns the new list. 

For example, if the function is sent this list:

[2,4,6,8,10]

and this list:

[5,6,7,8,9]

then the function will return this list:

[7,10,13,16,19]



b) 2%  Write the docstring for the function



c) 1% Write a single line of code (one statement) to call the function using the two example lists shown in part a)


Answer:
------



# part a)
def combine_lists(list1,list2):
    new_list = []
    for i in range(len(list1)):
        total = list1[i] + list2[i]
        new_list.append(total)
    return new_list


# part b)
''' (list,list) -> list
    This function receives two (non-empty) lists of integers.
    The lists are the same length.
    The function will create a new list which is composed of
    the addition of each element of the two lists.
    The function returns the new list. 
'''


# part c)
print(combine_lists([2,4,6,8,10],[5,6,7,8,9]))




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!