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

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

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

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

Student Number: Instructor: Brian Harrington

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

Student Number: 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

CSC148 Fall 2017 Ramp Up Session Reference

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

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

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Duration: 90 minutes. Page 1 of 14 Q2: /13 Q3: /13 TOTAL: /38. Bonus /1

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

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:

First Name: Last Name: Q1: /10

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

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.

Short Python function/method descriptions:

Strings are actually 'objects' Strings

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

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

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

Short Python function/method descriptions:

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

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

CS 1110 Prelim 2 November 14th, 2013

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

CS 1110 Prelim 1 October 15th, 2015

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

Scheme Quick Reference

PYTHON MOCK TEST PYTHON MOCK TEST III

CS 1110 Regular Prelim 1, March 14th, 2017

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

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

A first look at string processing. Python

Downloaded from Chapter 2. Functions

CS 1110 Prelim 1 October 17th, 2013

Functions. Systems Programming Concepts

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

CPD for GCSE Computing: Practical Sheet 6 February 14

CS 1110 Prelim 2 November 12th, 2015

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

Built-in Types of Data

Scheme Quick Reference

CS 1110 Prelim 1 October 12th, 2017

6-1 (Function). (Function) !*+!"#!, Function Description Example. natural logarithm of x (base e) rounds x to smallest integer not less than x

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

Introduction to String Manipulation

C++, How to Program. Spring 2016 CISC1600 Yanjun Li 1

CS 1110 Prelim 2 April 26th, 2016

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

Introduction to Programming

CS 1110 Prelim 2 November 12th, 2015

Abstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples

BIL 104E Introduction to Scientific and Engineering Computing. Lecture 4

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

Spring 2017 CS 1110/1111 Exam 1

Module 3: Strings and Input/Output

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

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

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

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

CS 1110 Final, December 17th, Question Points Score Total: 100

COLLEGE OF ENGINEERING, NASHIK-4

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

String Processing CS 1111 Introduction to Programming Fall 2018

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

Function Example. Function Definition. C Programming. Syntax. A small program(subroutine) that performs a particular task. Modular programming design

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

ENCM 339 Fall 2017 Lecture Section 01 Lab 9 for the Week of November 20

Programming for Engineers in Python. Recitation 2

Variable and Data Type I

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

Data Structures. Dictionaries - stores a series of unsorted key/value pairs that are indexed using the keys and return the value.

CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvani

How to Design Programs Languages

Advanced Python. Executive Summary, Session 1

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions.

EXAMINATION REGULATIONS and REFERENCE MATERIAL for ENCM 339 Fall 2017 Section 01 Final Examination

Structure and Interpretation of Computer Programs

6. Data Types and Dynamic Typing (Cont.)

C Functions. 5.2 Program Modules in C

Module 01: Introduction to Programming in Python

Structure and Interpretation of Computer Programs

Part I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming

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

CS Prelim 1 Review Fall 2018

Short Answer Questions (40 points)

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

Python Programming: Lecture 2 Data Types

Transcription:

CSCA08 Fall 2015 Term Test #2 Duration 110 minutes Aids allowed: none Last Name: Student Number: Markus Login: First Name: Please place a checkmark ( ) beside your tutorial session Tutorial Number Date/Time Room TA Name Check TUT0001 WE 16:00 17:00 IC 212 Umair Idris TUT0002 WE 19:00 20:00 MW 264 Eric Wang TUT0003 MO 10:00 11:00 PO 101 Shadman Shadid TUT0004 TU 9:00 10:00 AA 209 Maheshan Indralingam TUT0005 TH 17:00 18:00 IC 212 Andrew Wang TUT0006 TH 18:00 19:00 BV 361 Ekin Ozcelik TUT0007 TH 19:00 20:00 BV 361 Kalindu De Costa TUT0008 TU 12:00 13:00 MW 140 Shichong Peng TUT0009 FR 9:00 10:00 IC 208 Yasaman Mahdaviyeh TUT0010 FR 10:00 11:00 MW 120 Ayaan Chaudhry TUT0011 FR 13:00 14:00 BV 355 Umair Idris TUT0012 FR 14:00 15:00 IC 212 Ekin Ozcelik TUT0013 TU 9:00 10:00 IC 230 Vidhya Arulnathan TUT0014 TU 11:00 12:00 IC 326 David Kua TUT0015 TH 12:00 13:00 MW 160 Pat McGee TUT0016 TU 9:00 10:00 HW 215 Bo Zhao TUT0017 TH 18:00 19:00 HW 308 Ben Cooper TUT0018 FR 9:00 10:00 IC 120 Mohammed Faizan TUT0019 FR 10:00 11:00 BV 363 Tianxiang Gao TUT0021 FR 11:00 12:00 IC 230 Judy Duong TUT0022 WE 9:00 10:00 BV 260 Pat McGee TUT0023 MO 9:00 10:00 AA 208 Janarthanan Manoharan TUT0025 WE 15:00 16:00 IC 120 Judy Duong TUT0026 FR 14:00 15:00 BV 355 Charles Ruan Do not turn this page until you have received the signal to start. This exam consists of 3 questions on 12 pages (including this one). When you receive the signal to start, please make sure that your copy is complete. Proper documentation is required for all functions and code blocks. If you use any space for rough work, indicate clearly what you want marked. Any pages not attached to this cover page will not be marked. Please read all questions thoroughly before starting on any work. The University of Toronto s Code of Behaviour on Academic Matters applies to all University of Toronto Scarborough students. The Code prohibits all forms of academic dishonesty including, but not limited to, cheating, plagiarism, and the use of unauthorized aids. Students violating the Code may be subject to penalties up to and including suspension or expulsion from the University. # 1: / 5 # 2: /10 # 3: /15 TOTAL: /30 Total Pages = 12 Page 1 cont d...

[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.] Student #: Page 2 of 12 cont d...

Question 1. [5 marks] Write the output of the following code in the space provided. string1 = "ABCDE" string2 = "12345" for i in range(len(string1) - 1, -1, -1): count = 0 res = "" while(count < len(string2)): if(i < count): res += string1[i] elif(i == count): res += "X" else: res += string2[count] count += 1 print(res) Student #: Page 3 of 12 cont d...

[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.] Student #: Page 4 of 12 cont d...

Question 2. [10 marks] Write the output of the following code in the space provided. def func1(l1): l1[0] = "X" print(l1) def func2(l1, l2): l1[0] = l2[0] l3 = l1[0:3] l3[0] = "Y" l2[0] = l3[0] print(l1, l2, l3) def func3(l1, l2): l3 = l1[:] l1[0] = l2 l1[0][0] = "Z" l2[1] = "W" print(l1, l2, l3) l1 = [1, 2, 3] l2 = [7, 8, 9] func1(l1) func2(l1,l2) l1 = [1, 2, 3] l2 = [7, 8, 9] func3(l1, l2) l1 = [[1, 2], 3] l2 = [[7], [8, [9]]] func3(l1, l2) Student #: Page 5 of 12 cont d...

MANGLED CODE: count += 1 count = 1 def pig_latin(input_string): else: else: first_vowel_index = count for next_line in test_file: for next_word in next_line_words: found_vowel = False found_vowel = True if( name == " main "): if(input_string[0] in "aeiou"): if(input_string[count] in "aeiou"): next_line_words = next_line.split() print(result) result += "ay" result += pig_latin(next_word) + " " result = "" result = input_string + "w" result = input_string[first_vowel_index:] + input_string[0:first_vowel_index] return result test_file = open("test_file.txt", "r") test_file.close() while(count < len(input_string) and not found_vowel): RULES OF PIG LATIN Words beginning with a vowel, have way put on the end ( one becomes oneway ) Words with no vowels, have ay put on the end ( xkcd becomes xkcday ) All other words have all of the letters before the first vowel moved to the end, and ay put on the end ( brian becomes ianbray ) The code only works with lower case letters Student #: Page 6 of 12 cont d...

Question 3. [15 marks] Nick wrote this cool function that translates words into pig latin, and he wrote some global code to test it out, by translating every word in a file into pig latin. However, when he wasn t looking, the CODE MANGLER messed up all his code. He deleted all the comments, removed all indentation, and scrambled the lines. Your task is to re-construct Nick s code from the jumbled mess left by the code mangler (on the previous page). The rules of pig latin are also available on the previous page. Student #: Page 7 of 12 cont d...

[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.] Student #: Page 8 of 12 cont d...

[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.] Student #: Page 9 of 12 cont d...

[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.] Student #: Page 10 of 12 cont d...

Short Python function/method descriptions: You may tear this page off, but if you do so, you must not include any work on it (front or back) that you wish to have marked. builtins : abs(number) -> number Return the absolute value of the given number. max(a, b, c,...) -> value With two or more arguments, return the largest argument. min(a, b, c,...) -> value With two or more arguments, return the smallest argument. isinstance(object, class-or-type-or-tuple) -> bool Return whether an object is an instance of a class or of a subclass thereof. With a type as second argument, return whether that is the object's type. int(x) -> int Convert a string or number to an integer, if possible. A floating point argument will be truncated towards zero. str(x) -> str Convert an object into a string representation. str: S.count(sub[, start[, end]]) -> 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[,i]) -> 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.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 S converted to lowercase. S.replace(old, new) -> str Return a copy of string S with all occurrences of the string old replaced with the string new. S.split([sep]) -> list of str Return a list of the words in S, using string sep as the separator and any whitespace string if sep is not specified. S.startswith(prefix) -> bool Return True if S starts with the specified prefix and False otherwise. S.strip() --> str Return a copy of S with leading and trailing whitespace removed. S.upper() --> str Return a copy of S converted to uppercase. Total Pages = 12 Page 11 cont d...

list: append(...) L.append(object) -- append object to end count(...) L.count(value) -> integer -- return number of occurrences of value index(...) L.index(value, [start, [stop]]) -> integer -- return first index of value. Raises ValueError if the value is not present. insert(...) L.insert(index, object) -- insert object before index pop(...) L.pop([index]) -> item -- remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. remove(...) L.remove(value) -- remove first occurrence of value. Raises ValueError if the value is not present. math: ceil(...) Return the ceiling of x as an int. This is the smallest integral value >= x. cos(...) Return the cosine of x (measured in radians). floor(...) Return the floor of x as an int. This is the largest integral value <= x. pow(...) Return x**y (x to the power of y). sin(...) Return the sine of x (measured in radians). sqrt(...) Return the square root of x. tan(...) Return the tangent of x (measured in radians). set: pop(...) Remove and return an arbitrary set element. Raises KeyError if the set is empty. dict: keys(...) D.keys() -> a set-like object containing all of D's keys get(...) D.get(k[,d]) -> returns D[k] if k is in D, otherwise returns d. d defaults to None. object: init (...) x. init (...) initializes x; called automatically when a new object is created str (...) x. str () <==> str(x) other: x // y = integer divide x by y (i.e., how many times does x divide evenly into y). 5 // 3 = 1 x % y = the remainder when x is integer divided by y. 5 % 3 = 2 Page 12 of 12 End of Examination