UTORid: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell

Similar documents
Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Student Number: Comments are not required except where indicated, although they may help us mark your answers.

Student Number: Instructor: Brian Harrington

CSC148 Fall 2017 Ramp Up Session Reference

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Question 1. Part (a) Part (b) December 2013 Final Examination Marking Scheme CSC 108 H1F. [13 marks] [4 marks] Consider this program:

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number:

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Do not turn this page until you have received the signal to start.

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number:

UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2014 EXAMINATIONS. CSC 108 H1S Instructors: Campbell and Papadopoulou.

Do not turn this page until you have received the signal to start.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Do not turn this page until you have received the signal to start.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Do not turn this page until you have received the signal to start.

Strings are actually 'objects' Strings

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2017 EXAMINATIONS. CSC 108 H1F Instructor(s): Campbell, Fairgrieve, and Smith

Question 1. December 2009 Final Examination Marking Scheme CSC 108 H1F

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number:

Short Python function/method descriptions:

Student Number: UTORid: Question 0. [1 mark] Read and follow all instructions on this page, and fill in all fields.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

You may not share any information or materials with classmates during the exam and you may not use any electronic devices.

You may not share any information or materials with classmates during the exam and you may not use any electronic devices.

Question 1. CSC 120H1 F Midterm Test Solutions Fall 2017

CS 1110 Prelim 2 November 14th, 2013

ICS 31 UC IRVINE. ############## YOUR UCINET #### K E Y #### ############## Second Midterm YOUR NAME YOUR STUDENT ID (8 DIGITS)

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number:

Short Python function/method descriptions:

PYTHON MOCK TEST PYTHON MOCK TEST III

CS 1110 Prelim 1 October 15th, 2015

STRINGS. We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type.

Question 1. Part (a) Part (b) Part (c) April 2015 Final Examination Solutions CSC 108 H1S. [16 marks] [3 marks]

You submitted this homework on Tue 17 Sep :31 PM EET (UTC +0200). You got a score of out of

7. String Methods. Methods. Methods. Data + Functions Together. Designing count as a Function. Three String Methods 1/22/2016

CS 1110 Prelim 1 October 17th, 2013

UTORid: Comments are not required except where indicated, although they may help us mark your answers.

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

7. String Methods. Topics: Methods and Data More on Strings Functions and Methods The String Class

Python Day 3 11/28/16

Module 3: Strings and Input/Output

String Processing CS 1111 Introduction to Programming Fall 2018

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

18.1. CS 102 Unit 18. Python. Mark Redekopp

python 01 September 16, 2016

Strings. Upsorn Praphamontripong. Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break

Midterm 1 Review. Important control structures. Important things to review. Functions Loops Conditionals

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid:

******************** YOUR UCINET ID TIME MWF AT: 8A P ****** K E Y ****** TA S NAME ******************** Second Midterm

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully.

CSC148 Recipe for Designing Classes

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Prelim 2 April 26th, 2016

Scripting Languages. Python basics

Student Number: Legibly write your name and student number on this page. Legibly write your name on the back page of this exam.

Python Strings. Stéphane Vialette. LIGM, Université Paris-Est Marne-la-Vallée. September 25, 2012

CSCA20 Worksheet Strings

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

COLLEGE OF ENGINEERING, NASHIK-4

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Student Number: Lab day:

CSSE 120 Introduction to Software Development Practice for Test 1 paper-and-pencil part Page 1 of 6

from scratch A primer for scientists working with Next-Generation- Sequencing data Chapter 1 Text output and manipulation

Spring Semester 11 Exam #1 Dr. Dillon. (02/15)

'...' "..." escaping \u hhhh hhhh '''...''' """...""" raw string Example: r"abc\txyz\n" in code;

Babu Madhav Institute of Information Technology, UTU 2015

CS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:

Question 1. CSC A08 F Midterm Test Solutions Fall 2011

UNIVERSITY OF TORONTO Faculty of Arts and Science

Python review. 1 Python basics. References. CS 234 Naomi Nishimura

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck!

IPSL python tutorial: some exercises for beginners

CS 1110 Prelim 1 October 12th, 2017

Overview of List Syntax

Introduction to programming using Python

Structure and Interpretation of Computer Programs

Variable and Data Type I

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CMSC 202 Midterm Exam 1 Fall 2015

Intro to Strings. CSE 231 Rich Enbody. String: a sequence of characters. Indicated with quotes: or " " 9/11/13

CPD for GCSE Computing: Practical Sheet 6 February 14

CS 115 Lecture 13. Strings. Neil Moore. Department of Computer Science University of Kentucky Lexington, Kentucky

Structure and Interpretation of Computer Programs

You may not share any information or materials with classmates during the exam and you may not use any electronic devices.

Python Programming: Lecture 2 Data Types

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed

Strings and Testing string methods, formatting testing approaches CS GMU

Introduction to Computer Programming for Non-Majors

Introductory Linux Course. Python I. Martin Dahlö UPPMAX. Author: Nina Fischer. Dept. for Cell and Molecular Biology, Uppsala University

CS 1301 Exam 1 Fall 2010

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm

Second Midterm. Good luck! ICS 31 UC IRVINE YOUR NAME YOUR STUDENT ID (8 DIGITS) YOUR UCINET

Transcription:

CSC 108H1 F 2017 Midterm Test Duration 50 minutes Aids allowed: none Last Name: UTORid: First Name: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell Do not turn this page until you have received the signal to start. (Please fill out the identification section above, write your name on the back of the test, and read the instructions below.) Good Luck! This midterm is double-sided, and consists of 6 questions and a list of function/method descriptions. When you receive the signal to start, please make sure that your copy is complete. Comments are not required except where indicated, although they may help us mark your answers. No error checking is required: assume all user input and all argument values are valid. If you use any space for rough work, indicate clearly what you want marked. Do not remove any pages from the exam booklet. You may use a pencil; however, work written in pencil will not be considered for remarking. # 1: / 6 # 2: / 2 # 3: / 3 # 4: / 4 # 5: / 5 # 6: / 3 TOTAL: /23 Total Pages = 8

Question 1. [6 marks] Beside each code fragment in the table below, write what is printed when the code fragment is executed. If the code would cause an error, write ERROR and give a brief explanation. Code Output or Cause of Error s = 'two' v = int(s) print(v) x = '1' + 2 print(x) list1 = [1, 2, 3, 4] element = list1[1:][1] print(element) L = ['a', 'b'] L = L.append('c') print(l) for value in range(7, 2, -2): print(value) result = 'banana'.find('an', 2) print(result) Page 2 of 8

Question 2. [2 marks] Complete the docstring examples with arguments that will cause the function calls to return the values shown. def midterm_function(s1: str, s2: str) -> bool: Precondition: len(s1) >= 1 and len(s2) >= 1 >>> midterm_function(, ) True >>> midterm_function(, ) False return s1[0].isdigit() and s2[-1].isalpha() Question 3. [3 marks] Step 1 of the Function Design Recipe (docstring examples) has been completed for the function repeat_first_letter. Complete steps 2 and 3 of the Function Design Recipe: Fill in the function header (including the type contract) and write a good description. Do not write the function body. Do not include preconditions. def repeat_first_letter >>> repeat_first_letter('abc', 2) 'aabc' >>> repeat_first_letter('', 5) '' >>> repeat_first_letter('cs', 4) 'CCCCS' # DO NOT WRITE THE BODY OF THIS FUNCTION Page 3 of 8

Question 4. [4 marks] Complete the following function according to its docstring. def practice_time(age: int, beginner: bool) -> int: Return the practice time (in minutes) for a player of the given age who may or may not be a beginner player, according to the practice times in the following table: age of player practice time for a beginner player ------------- ----------------------------------- under 6 years 30 minutes 6 to 8 years, inclusive 50 minutes over 8 years 75 minutes Add 15 minutes to the practice time for a player who is not a beginner. Precondition: age >= 0 >>> practice_time(8, True) 50 >>> practice_time(9, True) 75 >>> practice_time(7, False) 65 Page 4 of 8

Question 5. [5 marks] Complete the following function according to its docstring. def has_letter_cases(s: str) -> bool: Return True if and only if s contains at least one lowercase letter and at least one uppercase letter. >>> has_letter_cases('abcdef') True >>> has_letter_cases('abc123') False >>> has_letter_cases('abcxyz') False Page 5 of 8

Question 6. [3 marks] Fill in the box with the while loop condition required for the function to work as described in its docstring. def find_first_fluffy(msg: str) -> int: Return the index of the first fluffy character (f, l, u, y) in msg, or the length of msg if it does not contain any fluffy characters. Fluffy characters are those that appear in the word 'fluffy'. >>> find_first_fluffy('firefly') 0 >>> find_first_fluffy('cats') 4 >>> find_first_fluffy('fully') 1 i = 0 while : i = i + 1 return i Page 6 of 8

[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.] Page 7 of 8

Last Name: First Name: Short Python function/method descriptions: builtins : int(x: object) -> int Convert x to an integer, if possible. A floating point argument will be truncated towards zero. len(x: object) -> int Return the length of list, tuple, or string x. print(values: object) -> None Prints the values. range([start: int], stop: int, [step: int]) -> list-like-object of int Return the integers starting with start and ending with stop - 1 with step specifying the amount to increment (or decrement). If start is not specified, the sequence starts at 0. If step is not specified, the values are incremented by 1. str(x: object) -> str Return an object converted to its string representation, if possible. str: x in s -> bool Produce True if and only if string x is in string s. S.count(sub: str[, start: int[, end: int]]) -> int Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation. S.find(sub: str[,i: int]) -> int Return the lowest index in S (starting at S[i], if i is given) where the string sub is found or -1 if sub does not occur in S. S.isalpha() -> bool Return True if and only if all characters in S are alphabetic and there is at least one character in S. S.isalnum() -> bool Return True if and only if all characters in S are alphanumeric and there is at least one character is S. S.isdigit() -> bool Return True if and only if all characters in S are digits and there is at least one character in S. S.islower() -> bool Return True if and only if all cased characters in S are lowercase and there is at least one cased character in S. S.isupper() -> bool Return True if and only if all cased characters in S are uppercase and there is at least one cased character in S. S.lower() -> str Return a copy of the string S converted to lowercase. S.replace(old: str, new: str) -> str Return a copy of string S with all occurrences of the string old replaced with the string new. S.upper() -> str Return a copy of the string S converted to uppercase. list: x in L -> bool Produce True if and only if object x is in list L L.append(item: object) -> None Append item to end of list L. L.extend(items: iterable) -> None Extend list L by appending elements from items. Strings and lists are iterables whose elements are characters and list items respectively. Total Pages = 8 End of Test