CSC108H1_09SUMMER1_608

CSC108H1_09SUMMER1_608 - 80 16 : ID Te st IN PL D Test ID:...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 80 16 : ID Te st IN PL D Test ID: 1680 Test ID: D load 1680 t ID: Down IN Duration — fifty minutes Examination Aids: 2985 168 er ID: 0 EA SE N A CSC 108H1Y Instructor: Daniel Zingaro Tes H H A N UNIVERSITY OF TORONTO Faculty of Arts and Science 1680 PL ID: SE EA Test None. Te st ID : 16 80 Student Number: Test ID: 1680 Do wn lo ad om First (Given) Name(s): er : 29 85 85 st ID Downloader ID: 2985 y. c Marking Guide : 16 80 29 /5 85 • Read the entire exam before you start. ID /6 r # 3: de ut or /7 : on # 2: • Not all questions are of equal value, so budget your time accordingly. /7 TOTAL: /25 • If you use any space for rough work, indicate clearly what you want marked. Te st ID Do w nl oa # 4: • You do not need to add import lines or do error checking Good Luck! # 1: ID lo wn Do st Te to • Check to make sure that you have all 6 pages. 29 0 .s tu 168 85 t ID: ID Tes : Do wn lo ad e r ID : 80 This examination consists of 4 questions on 6 pages (including this one). Instructions: er 16 de nt bu dd : ID 29 st Te Do not turn this page until you have received the signal to start. (In the meantime, please fill out the identification section above, and read the instructions below carefully.) ad ID : 16 80 Last (Family) Name(s): 85 : 16 : 29 ID 80 er ad lo wn Do Downl oader ID: 2985 UofT Student Buddy @ http://utoronto.studentbuddy.com This test is copyrighted by the uploader and/or course instructor. Downloader id is shown and also encrypted throughout the document. Unauthorized reproduction/distribution is strictlyPage 1 prohibited. Solution (if any) is NOT audited, so use at your discretion. cont’d. . . 2985 ader ID: Downlo r ID: ade nlo Dow 5 298 : 80 16 ID st Te CSC 108H1Y JUNE 2009 Te Midterm Exam st ID 80 : 16 16 : 8 ID st Te 85 : 29 ID Question 1. er ad lo wn Do [5 marks] Dow nlo ade r ID: Complete the following function according to its docstring description. 298 5 def rep_chars (s, num): ’’’Return a string consisting of each character of s repeated num times. For example, rep_chars (’abc’, 2) returns aabbcc’’’ 80 : 16 ID st Te nlo ade r ID: 298 5 ID: 1680 Dow Test Do wn lo ad er ID : 29 80 85 85 29 : ID om er 16 ad lo wn Do wn lo ad e r ID : 85 : 29 ID er ad lo Do wn y. c de nt bu dd 29 85 st ID : Do Dow ade nlo r ID: 298 16 80 5 Down 168 Tes ID: ID Test 1680 er ID: 2985 85 29 29 85 ID : : ID er ad lo wn Do r ID ut or 29 load : Te Down de er ad ade 1680 Test ID: 1680 nl oa lo nlo ID: 85 Test Do w wn Dow 0 t ID: : 2985 st er ID: on Do to .s tu load r ID: 298 5 Downlo ader ID: 2985 UofT Student Buddy @ http://utoronto.studentbuddy.com This test is copyrighted by the uploader and/or course instructor. Downloader id is shown and also encrypted throughout the document. Unauthorized reproduction/distribution is strictly prohibited. Page 2 of 6 Te st ID Solution (if any) is NOT audited, so use at your discretion. : 16 80 cont’d. . . 2 : ID lo ad er wn Do JUNE 2009 CSC 108H1Y Te st ID : 16 80 Midterm Exam 80 16 : ID st Tes t ID: 168 0 Te Question 2. [7 marks] Dow nlo ade r ID: Te st 298 5 ID : 16 80 Te st ID : 16 80 The left-hand column in the table below shows a series of statements to be interpreted by the Python shell. For each print statement, show the expected output in the right-hand column. t ID: Tes Do wn lo ad er ID : 29 85 0 168 ID Te : st 16 80 ID : 16 80 Output Te st Python statements Te st ID : 16 80 print 3 + 8.0 print True and True or False Down load 2985 80 er ID: 298 ID : Te 85 x=5 x=x+x+1+x x+3 print x st ID : 29 : ID Tes t ID: 168 0 ad e r ID : de nt bu dd 29 16 80 Do wn lo ad er ID : 29 85 Do wn lo print ’abc’.find(’b’) * 3 16 : ID 85 29 : ID r Do w nl oa de ut or 5 1680 st on to 1680 Down 98 ID: 80 Test Te ID: .s tu Test x = [1, 2, 3] y = x[2] y += 1 print x nlo y. c 85 st 80 16 Test ID: 1680 Te st ID : Dow om 16 r ID: ade Do wn lo ad er load er ID: 2985 Test ID: 1680 Do wn lo ad er ID : 29 85 Dow nlo ade r ID: 298 5 Downloader ID: 2985 UofT Student Buddy @ http://utoronto.studentbuddy.com Test ID: 1680 This test is copyrighted by the uploader and/or course instructor. Downloader id is shown and also encrypted throughout the document. Unauthorized reproduction/distribution is strictly prohibited. Page 3 of 6 Test ID: 1680 Solution (if any) is NOT audited, so use at your discretion. cont’d. . . 5 CSC 108H1Y JUNE 2009 Midterm Exam ID: 1680 Te st Do wn lo ad er ID : ID : 16 80 29 85 Test Question 3. 5 298 r ID: ade nlo [6 marks] Dow 85 : 29 ID er ad lo wn Do The function below makes a picture look like it was taken at sunset. Test ID: 1680 import media Test ID: 1680 80 : 16 ID Te st def make_sunset(pic): Te st ID : 16 80 for pixel in pic: Dow nlo ade r ID: 298 5 Do wn lo ad er ID : 29 85 Dow nlo ade r ID: 298 # get pixel’s old green value green = media.get_green(pixel) 5 Do wn lo ad er ID : 29 85 16 ID : ID : st Te om # set pixel to new green value media.set_green(pixel, int(green * 0.7)) 168 0 80 Tes t ID: 80 16 y. c 0 168 t ID: Tes 16 80 Do wn lo ad er 29 85 : ID : de nt bu dd ID : 29 85 st # get pixel’s old blue value blue = media.get_blue(pixel) Te st 5 298 r ID: ade nlo Dow Do wn lo ad e r ID # set pixel to new blue value media.set_blue(pixel, int(blue * 0.7)) Part (a) [3 marks] Tes t ID: 168 0 Downloader Test ID: ID: 2985 1680 st Te : ID 80 Dow nlo ade r ID: 298 16 ID : Do w nl oa de ut or r ID : on 80 16 85 st ID : 1680 Test ID: Te st to Te .s tu 5 29 80 16 The function does not return anything (it has no return statement). Clearly explain how this function is able to do its job in spite of this. Refer to specific properties of pictures in your answer. Test ID: 1680 Test ID: 1680 Part (b) [3 marks] In the lines that use set_green and set_blue, why do we use the int function? Explain the purpose of int, and what might happen if we did not include it. Do wn lo ad er ID : 29 85 UofT Student Buddy @ http://utoronto.studentbuddy.com This test is copyrighted by the uploader and/or course instructor. Downloader id is shown and also encrypted throughout the document. Unauthorized reproduction/distribution is strictly prohibited. Page 4 of 6 Solution (if any) is NOT audited, so use at your discretion. Test ID: 1680 cont’d. . . 298 Dow nlo ade r ID: 5 Downloader ID: 2985 ID: 1680 Test JUNE 2009 CSC 108H1Y Midterm Exam 80 : 16 ID st Te Question 4. [7 marks] Complete the following function according to its docstring description. The function is designed to ask for a valid password (presumably for a user setting up a new account of some sort) until one is given, or the user reaches the maximum guesses allowed. You must use a while-loop in your solution. You may assume that max_attempts is at least 1. 0 168 t ID: Tes : 16 80 ID st : Do wn lo ad er ID 29 85 Te def get_password (max_attempts): ’’’Prompt the user for a valid password until a valid one is given or they have entered max_attempts invalid passwords. A valid password is one that is at least length 6 and is not the word "password". Each time the user gives an invalid password, tell them that it was invalid and prompt again if they have not reached max_attempts tries. If the user gives max_attempts invalid passwords, return the empty string; otherwise return the valid password they gave’’’. Te st ID : 16 80 16 ade r ID: 298 5 ID: 2985 ID : Downl oader om nlo 80 Dow Te 2985 ader ID: Downlo st ID : y. c st 80 16 nlo Dow ad e r ID : de nt bu dd r ID: ade Do wn 5 lo 298 er ID: 2985 85 29 ID : er ad lo 0 Tes t ID: 168 : 16 80 ID: 1680 16 : ID 85 st 29 Te : ID r de nl oa ID Downloader ID: 2985 Do w Test Te st ut or on to .s tu 80 load Down Do wn 29 85 Test ID: 1680 Test ID: 1680 UofT Student Buddy @ http://utoronto.studentbuddy.com This test is copyrighted by the uploader and/or course instructor. Downloader id is shown and also encrypted throughout the document. Unauthorized reproduction/distribution is strictly prohibited. Page 5 of 6 Solution (if any) is NOT audited, so use at your discretion. Tes t ID: 168 0 cont’d. . . Test ID: 1680 85 ID: 2985 Do wn lo ad er ID : 29 oader Downl CSC 108H1Y JUNE 2009 Downl oader ID: 2985 Midterm Exam [Use the space below for rough work. This page will not be marked, unless you clearly indicate the part of your work that you want us to mark.] 85 : ID 29 er ad lo wn Tes t ID: 168 0 Do Downloader ID: 2985 168 Tes 0 t ID: 0 168 t ID: Tes st Te : ID om 80 80 16 ID: 1680 Te 85 st Test y. c ID : 16 Downloader ID: 2985 st ID : 16 80 29 Te st 16 80 ad e r ID : de nt bu dd ID : 80 : 16 ID st Downloader 16 : ID 85 st 29 Te ID : 16 80 : ID r wn lo ad er ID : 29 85 nl oa Do Do w Te st de ut or on to .s tu 80 Do wn lo Te Tes t ID: 168 0 Test ID: 1680 Downloader ID: 2985 Do wn lo ad er ID : 29 85 UofT Student Buddy @ http://utoronto.studentbuddy.com This test is copyrighted by the uploader and/or course instructor. Downloader id is shown and also encrypted throughout the document. Unauthorized reproduction/distribution is strictly prohibited. Page 6 of 6 Solution (if any) is NOT audited, so use at your discretion. End of Examination ID: 2985 ...
View Full Document

This note was uploaded on 11/27/2010 for the course CS 108 taught by Professor Paulgries during the Spring '08 term at University of Toronto.

Ask a homework question - tutors are online