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

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

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

This document is current at: 
Friday 29th June 2018, 10:48 PT, AD

REFRESH THIS PAGE OFTEN FOR LATEST VERSION

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

CSCI120 QUIZ 2
==============


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 2 covers all topics covered in the course so far, 
up to and including Strings. 

*** The focus of Quiz 2 is functions, lists and strings ***

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


*** The topics of Files and Searching are NOT on Quiz 2. 
These topics will be included on Quiz 3 and on the Final exam. ***

All topics from this course 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 2.
  


The format of Quiz 2 is as follows:



Quiz 2
======

(6% of final grade, 90 minutes)


Questions are based on the course notes and assignments.

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

Valid photo ID is required.

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






Example Quiz 2 questions:



1. What will be the output when the following code runs?

s = "When can I get rest?"
print(s[5])
print(s[6:12])
print(s[9:])
print(s[0:5].islower())
print(s.count("e"))
s = s.replace("e","X")
print(s)
print(s[20])

Answer:

c
an I g
I get rest?
False
3
WhXn can I gXt rXst?
index out of range
>>> 



 

2.  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:    [2] [12, 14]





3. (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.



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

Answer: 

while 1:
	print ("error!")




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

Answer:

attempt to divide by zero 





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

Answer:

attempt to divide by a string object  



7. Using either a while loop or a for loop, 
write Python 3 code to allow a user to enter 5 strings.  
As each string is entered 
it is appended to a list called myStringList.  
The following is an example run, 
user input is shown in bold font... 
(Do not attempt to change any colours in your program code.) 


Please enter string #1: Yesterday 
Please enter string #2: all
Please enter string #3: my
Please enter string #4: troubles 
Please enter string #5: evaporated  



Answer:

myStringList = []
n = 0
while n < 6:
   n = n + 1
   s = input("Please enter a string #" + str(n) + ": ")
   myStringList.append(s)
print(myStringList)

####  or use a for loop...

myStringList = []
for n in range(1,7):
   s = input("Please enter a string #" + str(n) + ": ")
   myStringList.append(s)
print(myStringList)









GPA
===
Your attendance, conduct and progress are monitored throughout the course.
You may inspect your status report at any time using the online Gradebook
The date of the quiz is shown in the course schedule - latest details on C4.

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

Good Luck!

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

End of document

 

 


 




































Valid HTML5!

Valid CSS!