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

Size: px
Start display at page:

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

Transcription

1 CSC 108H5 F 2018 Midterm Test Duration 90 minutes Aids allowed: none Student Number: utorid: Last Name: First Name: Do not turn this page until you have received the signal to start. (Please fill out the identification section above and read the instructions below.) Good Luck! This midterm consists of 5 questions on 9 pages (including this one). 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. You may assume all relevant import statements have been performed. 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. You may use a pencil; however, work written in pencil may not be considered for remarking. # 1: /13 # 2: / 7 # 3: / 4 # 4: / 6 # 5: /10 TOTAL: /40 Total Pages = 9

2 Question 1. [13 marks] Assume each of the pieces of code below is being entered into the Python console. In each space, write what would be displayed on the console, if anything. If an error would be displayed to the console, write ERROR. Each subquestion is independent of the others. Part (a) [1 mark] >>> x = 5 >>> y = x >>> x = 2 >>> y Part (b) [2 marks] >>> x = 4 >>> y = 2 >>> z = x/y >>> y = x+y * z >>> x = 5 * z // 3 >>> y >>> x Page 2 of 9

3 Part (c) [3 marks] Assume the following two functions have been declared. def f1(x, y): x = y + 2 z = y * x return 2 * f2(x, z) def f2(y, x): x = x - y z = x - y return x - (y + z) >>> z = 1 >>> x = 2 >>> f1(z, x) Part (d) [2 marks] >>> s = "EZ Marks." >>> t = s[1:4] >>> t >>> t[2] Page 3 of 9

4 Part (e) [2 marks] >>> L = [5, 8, 3, 0, 1, 2, 6, 24] >>> for z in L: if z%3!= 0 and z%2 == 0: print(z) Part (f) [3 marks] >>> L = [[5, 9, 1, 1, 2], [7, 7], [], [1]] >>> for i in range(len(l[0])): s = 0 for n in L[i]: s += n print(s) Page 4 of 9

5 Question 2. [7 marks] Recall the is a number function from Assignment 1. The function takes in a string and returns True if and only if that string represents a positive number or positive decimal number (see some examples in the docstring below). Implement is a number without the use of loops, or try/exceptions. If your code uses either of these constructs, you will receive 0. Focus on passing the examples in the docstring. Do NOT worry about cases like 1.0, 4.0e7, etc. def is_a_number(s:str)-> bool: """ Returns True if and only if s is a string representing a positive number. Examples: >>> is_a_number("1") True >>> is_a_number("one") False >>> is_a_number("-3") False >>> is_a_number("3.") True >>> is_a_number("14.61") True >>> is_a_number("3.1.2") False """ Page 5 of 9

6 Question 3. [4 marks] Consider the function below. Reimplement (rewrite) it using only a single if statement. To get full grades there should not be any else or elif clauses, only a single if clause. The behaviour of your new function should be equivalent to the original function in the sense that given the same input, the two functions (original and new) will produce the same output. def my_fun(n: int, m: int)-> int: if n > 5 and m > 0: if n > 0: return 1 else: return 2 elif m <= 0 or n < 6: return 3 else: return 4 Page 6 of 9

7 Question 4. [6 marks] Consider the function below. Reimplement (rewrite) it using a while loop instead of a for loop. The behaviour of your new function should be equivalent to the original function in the sense that given the same input, the two functions (original and new) will produce the same output. def my_fun(s: str)-> int: n = 0 for char in s: if not char in "aeiouaeiou": n += 1 return n Page 7 of 9

8 Question 5. [10 marks] Implement the function below. def positive_average(l: List[List[int]])-> float: """ Takes in a nested list of integers L, and returns the average value of all positive numbers. If there are no positive numbers, it returns 0.0. The function does not consider 0 to be a positive number. Examples: >>> L = [[1, -2, 0], [9, -2], []] >>> positive_average(l) 5.0 >>> L = [[5, 9, 0, 1, 4, -9]] >>> positive_average(l) 4.75 >>> L = [[-6, -10, 0], [-65], [-10102, -4], [-8]] 0.0 """ Page 8 of 9

9 Short Python function/method descriptions: builtins : int(x) -> int Convert x to an integer, if possible. A floating point argument will be truncated towards zero. len(x) -> int Return the length of list, tuple, or string x. print(value) -> NoneType Prints the values. range([start], stop, [step]) -> 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) -> str Return an object converted to its string representation, if possible. str: x in s -> bool Return True if and only if x is in s. 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.isnumeric() -> bool Returns True if all characters in a string are numeric characters. If not, it returns False. S.lower() -> str Return a copy of S converted to lowercase. S.replace(old, new) -> str Return a copy of 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; use string sep as the separator and any whitespace string if sep is not specified. S.upper() -> str Return a copy of S converted to uppercase. S.startswith(sub) -> bool Return True if and only if S starts with the substring sub. list: x in L --> bool Return True if and only if x is in L L.append(object) -> NoneType Append object to end of L. L.pop(int) -> item Remove and return item at index (default last). Raises IndexError if list is empty or index is out of range. Total Pages = 9 End of Test

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. CSC 108H5 F 2014 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0101 Instructor: Dan Zingaro (9:00-10:00) Lecture Section: L0102 Instructor:

More information

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

UTORid: Lecture Section: (circle one): L0101 (MWF10) L0201 (MWF11) Instructor: Jacqueline Smith Jen Campbell 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

More information

Student Number: Instructor: Brian Harrington

Student Number: Instructor: Brian Harrington CSC A08 2012 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Instructor: Brian Harrington Do not turn this page until you have received the signal to start. (Please

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science SUMMER 2012 EXAMINATIONS CSC 108 H1Y Instructors: Janicki Duration NA PLEASE HAND IN Examination Aids: None Student Number: Family Name(s):

More information

CSC148 Fall 2017 Ramp Up Session Reference

CSC148 Fall 2017 Ramp Up Session Reference Short Python function/method descriptions: builtins : input([prompt]) -> str Read a string from standard input. The trailing newline is stripped. The prompt string, if given, is printed without a trailing

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2013 EXAMINATIONS CSC 108 H1F Instructors: Craig and Gries Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number:

More information

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

Question 1. Part (a) Part (b) December 2013 Final Examination Marking Scheme CSC 108 H1F. [13 marks] [4 marks] Consider this program: Question 1. Part (a) [4 marks] Consider this program: [13 marks] def square(x): (number) -> number Write what this program prints, one line per box. There are more boxes than you need; leave unused ones

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2012 EXAMINATIONS CSC 108 H1S Instructors: Campbell Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Family

More information

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

CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none. Student Number: CSC A20H3 S 2011 Test 1 Duration 90 minutes Aids allowed: none Last Name: Lecture Section: L0101 Student Number: First Name: Instructor: Bretscher Do not turn this page until you have received the signal

More information

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. CSCA08 Fall 2014 Final Exam Duration 160 minutes Aids allowed: none Student Number: A Instructor: Brian Harrington Last Name: First Name: UtorID (Markus Login): Do not turn this page until you have received

More information

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. CSCA48 Fall 2015 Final Exam Duration 150 minutes Aids allowed: none Student Number: Instructor: Brian Harrington and Anna Bretscher Last Name: First Name: UtorID (Markus Login): Do not turn this page until

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2010 EXAMINATIONS CSC 108 H1S Instructors: Horton Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Family Name(s):

More information

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

UNIVERSITY OF TORONTO SCARBOROUGH. December 2017 EXAMINATIONS. CSCA20H3 Duration 3 hours. Examination Aids: Instructor: Bretscher PLEASE HAND IN UNIVERSITY OF TORONTO SCARBOROUGH December 2017 EXAMINATIONS CSCA20H3 Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Last (Family) Name(s): First (Given) Name(s):

More information

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

UNIVERSITY OF TORONTO SCARBOROUGH. Wnter 2016 EXAMINATIONS. CSC A20H Duration 2 hours 45 mins. No Aids Allowed Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Wnter 2016 EXAMINATIONS CSC A20H Duration 2 hours 45 mins No Aids Allowed Do not turn this page until you have received the signal

More information

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. CSCA48 Winter 2015 Midterm Exam Duration 100 minutes Aids allowed: none Student Number: Instructors: Anna Bretscher & Brian Harrington Last Name: First Name: UtorID (Markus Login): Please place a checkmark

More information

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

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2009 EXAMINATIONS CSC 108 H1F Instructors: Gries, Horton, Zingaro Duration 3 hours PLEASE HAND IN Examination Aids: None Student

More information

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

Good Luck! CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none. Student Number: CSC207, Fall 2012: Quiz 1 Duration 25 minutes Aids allowed: none Student Number: Last Name: Lecture Section: L0101 First Name: Instructor: Horton Please fill out the identification section above as well

More information

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

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 APRIL 2014 EXAMINATIONS CSC 108 H1S Instructors: Campbell and Papadopoulou Duration 3 hours PLEASE HAND IN Examination Aids: None Student

More information

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

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. UNIVERSITY OF TORONTO MISSISSAUGA DECEMBER 2014 FINAL EXAMINATION CSC108H5F Instructor: Zingaro, Petersen, Tong Duration: 3 hours Examination Aids: None Student Number: Family Name(s): Given Name(s): The

More information

Short Python function/method descriptions:

Short Python function/method descriptions: Last Name First Name Student#. Short Python function/method descriptions: builtins : len(x) -> integer Return the length of the list, tuple, dict, or string x. max(l) -> value Return the largest value

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL/MAY 2009 EXAMINATIONS CSC 108H1S Instructor: Horton Duration 3 hours PLEASE HAND IN Examination Aids: None Student Number: Last (Family)

More information

Short Python function/method descriptions:

Short Python function/method descriptions: Last Name First Name Student#. Short Python function/method descriptions: builtins : len(x) -> integer Return the length of the list, tuple, dict, or string x. max(l) -> value Return the largest value

More information

Strings are actually 'objects' Strings

Strings are actually 'objects' Strings Strings are actually 'objects' Strings What is an object?! An object is a concept that we can encapsulate data along with the functions that might need to access or manipulate that data. What is an object?!

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science DECEMBER 2016 EXAMINATIONS CSC 108 H1F Instructor(s): Smith, Gries, de Lara Duration 3 hours PLEASE HAND IN No Aids Allowed You must earn

More information

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

Question 1. December 2009 Final Examination Marking Scheme CSC 108 H1F Question 1. [10 marks] Below are five segments of code. Each one runs without error. To the right of each segment, show the output it generates. L = [1, 2, 3, 4] for item in L: item = item * 5 print L

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2016 EXAMINATIONS CSC 108 H1S Instructor(s): Smith and Fairgrieve Duration 3 hours PLEASE HAND IN No Aids Allowed You must earn at

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science APRIL 2015 EXAMINATIONS CSC 108 H1S Instructor: Fairgrieve and Hagerman Duration 3 hours PLEASE HAND IN Examination Aids: None You must

More information

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

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 DECEMBER 2017 EXAMINATIONS CSC 108 H1F Instructor(s): Campbell, Fairgrieve, and Smith Duration 3 hours PLEASE HAND IN No Aids Allowed You

More information

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

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. CSC 148 H1 / L0101 Term Test # 2 13 March 2013 Duration: Aids Allowed: 50 minutes None Student Number: Last (Family) Name(s): First (Given) Name(s): Do not turn this page until you have received the signal

More information

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

CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none. Student Number: CSC 108H1 F 2009 Test 1 Duration 35 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0102 Instructor: Gries Do not turn this page until you have received the signal to

More information

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

Question 1. CSC 120H1 F Midterm Test Solutions Fall 2017 Question 1. [5 marks] Fill in the boxes below with what you would see in your Python shell if you were to type the following expressions. If that code would result in an error, then write ERROR and provide

More information

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

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

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

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Student Number: Lab day:

Student Number: Lab day: CSC 148H1 Summer 2008 Midterm Test Duration 60 minutes Aids allowed: none Last Name: Student Number: Lab day: First Name: Lecture Section: L0101 Instructor: R. Danek Do not turn this page until you have

More information

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

Midterm 1 Review. Important control structures. Important things to review. Functions Loops Conditionals Midterm 1 Review Important control structures Functions Loops Conditionals Important things to review Binary numbers Boolean operators (and, or, not) String operations: len, ord, +, *, slice, index List

More information

PYTHON MOCK TEST PYTHON MOCK TEST III

PYTHON MOCK TEST PYTHON MOCK TEST III http://www.tutorialspoint.com PYTHON MOCK TEST Copyright tutorialspoint.com This section presents you various set of Mock Tests related to Python. You can download these sample mock tests at your local

More information

A first look at string processing. Python

A first look at string processing. Python A first look at string processing Python Strings Basic data type in Python Strings are immutable, meaning they cannot be shared Why? It s complicated, but string literals are very frequent. If strings

More information

CPD for GCSE Computing: Practical Sheet 6 February 14

CPD for GCSE Computing: Practical Sheet 6 February 14 Aims Programming Sheet 6 Arrays in Python Section Aim 1 Arrays A variable with many values Understand the idea of an array as a way to combine many values that are assigned to as single variable. 2 While

More information

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

Student Number: UTORid: Question 0. [1 mark] Read and follow all instructions on this page, and fill in all fields. CSC 258H1 Y 2016 Midterm Test Duration 1 hour and 50 minutes Aids allowed: none Student Number: UTORid: Last Name: First Name: Question 0. [1 mark] Read and follow all instructions on this page, and fill

More information

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

CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none. Student Number: CSC 108H1 F 2010 Test 1 Duration 45 minutes Aids allowed: none Last Name: Lecture Section: L0101 Student Number: First Name: Instructors: Horton and Engels Do not turn this page until you have received

More information

Scripting Languages. Python basics

Scripting Languages. Python basics Scripting Languages Python basics Interpreter Session: python Direct conversation with python (>>>) Python 3.5.2 (default, Nov 23 2017, 16:37:01) [GCC 5.4.0 20160609] on linux Type "help", "copyright",

More information

Overview of List Syntax

Overview of List Syntax Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 4300112 x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 Append 2 to end of list x (now length 5) Evaluates

More information

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. ICS 31 UC IRVINE WINTER 2014 DAVID G. KAY Second Midterm YOUR NAME YOUR LAB: YOUR STUDENT ID (8 DIGITS) SECTION (1 TO 9) ******************** YOUR UCINET ID TIME MWF AT: 8 10 12 2 4 6 ****** K E Y ******

More information

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

Question 1. Part (a) Part (b) Part (c) April 2015 Final Examination Solutions CSC 108 H1S. [16 marks] [3 marks] Question 1. Part (a) [3 marks] [16 marks] Consider this Python code: L = [8, 12, 3] X = L.sort() Y = L[:] L.extend([1]) Write what this code prints when run, with one line per box. There may be more boxes

More information

CS 1110 Prelim 2 April 26th, 2016

CS 1110 Prelim 2 April 26th, 2016 Circle your lab/situation: CS 1110 Prelim 2 April 26th, 2016 ACCEL: Tue 12:20 Tue 1:25 Tue 2:30 Tue 3:35 ACCEL : Wed 10:10 Wed 11:15 Wed 12:20 Wed 1:25 Wed 2:30 Wed 3:35 PHILLIPS : Tue 12:20 Tue 1:25 Wed

More information

Module 3: Strings and Input/Output

Module 3: Strings and Input/Output Module 3: Strings and Input/Output Topics: Strings and their methods Printing to standard output Reading from standard input Readings: ThinkP 8, 10 1 Strings in Python: combining strings in interesting

More information

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

Spring Semester 11 Exam #1 Dr. Dillon. (02/15) Spring Semester 11 Exam #1 Dr. Dillon. (02/15) Form 1 A Last name (printed): First name (printed): Directions: a) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b) You may use one 8.5"

More information

UNIVERSITY OF TORONTO Faculty of Arts and Science

UNIVERSITY OF TORONTO Faculty of Arts and Science UNIVERSITY OF TORONTO Faculty of Arts and Science Midterm 2 s CSC148H1F Duration: 50 min. Instructors: Diane Horton, David Liu. Examination Aids: Provided aid sheet Name: Student Number: Please read the

More information

CS 1110 Prelim 1 October 15th, 2015

CS 1110 Prelim 1 October 15th, 2015 CS 1110 Prelim 1 October 15th, 2015 This 90-minute exam has 6 uestions worth a total of 100 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need more

More information

Python Programming: Lecture 2 Data Types

Python Programming: Lecture 2 Data Types Python Programming: Lecture 2 Data Types Lili Dworkin University of Pennsylvania Last Week s Quiz 1..pyc files contain byte code 2. The type of math.sqrt(9)/3 is float 3. The type of isinstance(5.5, float)

More information

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac

More information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

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

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. CSC A48 Winter 2014 CSCA48 Final Exam 23 April 2014 Duration: Aids Allowed: 150 minutes None Student Number: UTORid: Last (Family) Name(s): First (Given) Name(s): Do not turn this page until you have received

More information

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

STRINGS. We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type. HANDOUT 1 Strings STRINGS We ve already introduced the string data type a few lectures ago. Strings are subtypes of the sequence data type. Strings are written with either single or double quotes encasing

More information

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science

PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science PLEASE HAND IN UNIVERSITY OF TORONTO Faculty of Arts and Science AUGUST EXAMINATIONS CSC 108H1Y Instructor: Daniel Zingaro Duration three hours PLEASE HAND IN Examination Aids: None. Student Number: Last

More information

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

CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm CMSC330 Fall 2016 Midterm #1 2:00pm/3:30pm Name: Discussion Time: 10am 11am 12pm 1pm 2pm 3pm TA Name (Circle): Alex Austin Ayman Brian Damien Daniel K. Daniel P. Greg Tammy Tim Vitung Will K. Instructions

More information

CSCA20 Worksheet Strings

CSCA20 Worksheet Strings 1 Introduction to strings CSCA20 Worksheet Strings A string is just a sequence of characters. Why do you think it is called string? List some real life applications that use strings: 2 Basics We define

More information

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

ICS 31 UC IRVINE. ############## YOUR UCINET #### K E Y #### ############## Second Midterm YOUR NAME YOUR STUDENT ID (8 DIGITS) ICS 31 UC IRVINE SPRING 2017 DAVID G. KAY YOUR NAME YOUR STUDENT ID (8 DIGITS) ############## YOUR UCINET ID @UCI.EDU #### K E Y #### ############## Second Midterm You have 75 minutes (until the end of

More information

ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation ENGR 102 Engineering Lab I - Computation Learning Objectives by Week 1 ENGR 102 Engineering Lab I Computation 2 Credits 2. Introduction to the design and development of computer applications for engineers;

More information

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Python I. Some material adapted from Upenn cmpe391 slides and other sources Python I Some material adapted from Upenn cmpe391 slides and other sources Overview Names & Assignment Data types Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics

More information

Play with Python: An intro to Data Science

Play with Python: An intro to Data Science Play with Python: An intro to Data Science Ignacio Larrú Instituto de Empresa Who am I? Passionate about Technology From Iphone apps to algorithmic programming I love innovative technology Former Entrepreneur:

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

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

UNIVERSITY OF TORONTO SCARBOROUGH. Fall 2015 EXAMINATIONS. CSC A20H Duration 3 hours. No Aids Allowed Student Number: Last Name: First Name: UNIVERSITY OF TORONTO SCARBOROUGH Fall 2015 EXAMINATIONS CSC A20H Duration 3 hours No Aids Allowed Do not turn this page until you have received the signal to start.

More information

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

First name (printed): a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. CSE 231 F 13 Exam #1 Last name (printed): First name (printed): Form 1 X Directions: a. DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN. b. This exam booklet contains 25 questions, each

More information

Introduction to: Computers & Programming: Review prior to 1 st Midterm

Introduction to: Computers & Programming: Review prior to 1 st Midterm Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in

More information

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

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. CSC 165 H1 Term Test 2 / L5101 Fall 2011 Duration: Aids Allowed: 60 minutes none Student Number: Family Name(s): Given Name(s): Do not turn this page until you have received the signal to start. In the

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

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

CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, Good Luck! CS 303E Fall 2011 Exam 2 Solutions and Criteria November 2, 2011 Name: EID: Section Number: Friday discussion time (circle one): 9-10 10-11 11-12 12-1 2-3 Friday discussion TA(circle one): Wei Ashley Answer

More information

Strings and Testing string methods, formatting testing approaches CS GMU

Strings and Testing string methods, formatting testing approaches CS GMU Strings and Testing string methods, formatting testing approaches CS 112 @ GMU Topics string methods string formatting testing, unit testing 2 Some String Methods (See LIB 4.7.1) usage: stringexpr. methodname

More information

Advanced Python. Executive Summary, Session 1

Advanced Python. Executive Summary, Session 1 Advanced Python Executive Summary, Session 1 OBJECT: a unit of data of a particular type with characteristic functionality (i.e., methods and/or use with operators). Everything in Python is an object.

More information

Python and Bioinformatics. Pierre Parutto

Python and Bioinformatics. Pierre Parutto Python and Bioinformatics Pierre Parutto October 9, 2016 Contents 1 Common Data Structures 2 1.1 Sequences............................... 2 1.1.1 Manipulating Sequences................... 2 1.1.2 String.............................

More information

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

Strings. Upsorn Praphamontripong. Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break Note: for reference when we practice loop. We ll discuss Strings in detail after Spring break Strings Upsorn Praphamontripong CS 1111 Introduction to Programming Spring 2018 Strings Sequence of characters

More information

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

Python allows variables to hold string values, just like any other type (Boolean, int, float). So, the following assignment statements are valid: 1 STRINGS Objectives: How text data is internally represented as a string Accessing individual characters by a positive or negative index String slices Operations on strings: concatenation, comparison,

More information

CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 115 Lecture 8. Selection: the if statement. Neil Moore CS 115 Lecture 8 Selection: the if statement Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 24 September 2015 Selection Sometime we want to execute

More information

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

You submitted this homework on Tue 17 Sep :31 PM EET (UTC +0200). You got a score of out of Feedback Week 4 Exercise You submitted this homework on Tue 17 Sep 2013 11:31 PM EET (UTC +0200). You got a score of 14.00 out of 14.00. Trace the code by hand (on paper) and then use the visualizer or

More information

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

Part I. Wei Tianwen. A Brief Introduction to Python. Part I. Wei Tianwen. Basics. Object Oriented Programming 2017 Table of contents 1 2 Integers and floats Integer int and float float are elementary numeric types in. integer >>> a=1 >>> a 1 >>> type (a) Integers and floats Integer int and float

More information

Introduction to Programming, Aug-Dec 2006

Introduction to Programming, Aug-Dec 2006 Introduction to Programming, Aug-Dec 2006 Lecture 3, Friday 11 Aug 2006 Lists... We can implicitly decompose a list into its head and tail by providing a pattern with two variables to denote the two components

More information

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet)

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet) CS1114 Spring 2015 Test ONE ANSWER KEY page 1 of 8 pages (counting the cover sheet) For the following questions, use these variable definitions a = 36 b = 3 c = 12 d = '3' What is the type and value of

More information

Python Working with files. May 4, 2017

Python Working with files. May 4, 2017 Python Working with files May 4, 2017 So far, everything we have done in Python was using in-memory operations. After closing the Python interpreter or after the script was done, all our input and output

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

Review 4. Lists and Sequences

Review 4. Lists and Sequences Review 4 Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 x[k] = 2 * x[0] x[k 2] = 6 Create list of length 4 with all zeroes Append 2 to end of list

More information

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts

Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Review Sheet for Midterm #1 COMPSCI 119 Professor William T. Verts Simple Data Types There are a number of data types that are considered primitive in that they contain only a single value. These data

More information

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

CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvani CIS192: Python Programming Data Types & Comprehensions Harry Smith University of Pennsylvania September 6, 2017 Harry Smith (University of Pennsylvania) CIS 192 Fall Lecture 2 September 6, 2017 1 / 34

More information

String Processing CS 1111 Introduction to Programming Fall 2018

String Processing CS 1111 Introduction to Programming Fall 2018 String Processing CS 1111 Introduction to Programming Fall 2018 [The Coder s Apprentice, 10] 1 Collections Ordered, Dup allow List Range String Tuple Unordered, No Dup Dict collection[index] Access an

More information

IPSL python tutorial: some exercises for beginners

IPSL python tutorial: some exercises for beginners 1 of 9 10/22/2013 03:55 PM IPSL python tutorial: some exercises for beginners WARNING! WARNING! This is the FULL version of the tutorial (including the solutions) WARNING! Jean-Yves Peterschmitt - LSCE

More information

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1

Lecture #15: Generic Functions and Expressivity. Last modified: Wed Mar 1 15:51: CS61A: Lecture #16 1 Lecture #15: Generic Functions and Expressivity Last modified: Wed Mar 1 15:51:48 2017 CS61A: Lecture #16 1 Consider the function find: Generic Programming def find(l, x, k): """Return the index in L of

More information

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

Student Number: Legibly write your name and student number on this page. Legibly write your name on the back page of this exam. CSC207H1 S 2015 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Do not turn this page until you have received the signal to start. (Please fill out the identification

More information

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

Do not turn this page until you have received the signal to start. In the meantime, please read the instructions below carefully. CSC A48 Winter 2014 CSCA48 Midterm Test 15 February 2014 Duration: Aids Allowed: 70 minutes None Student Number: UTORid: Last (Family) Name(s): First (Given) Name(s): Do not turn this page until you have

More information

CS 1110 Prelim 1, March 2018

CS 1110 Prelim 1, March 2018 Last Name: First Name: Cornell NetID, all caps: CS 1110 Prelim 1, March 2018 This 90-minute exam has 7 questions worth a total of 69 points. You may separate the pages while working on the exam; we have

More information

Key Differences Between Python and Java

Key Differences Between Python and Java Python Python supports many (but not all) aspects of object-oriented programming; but it is possible to write a Python program without making any use of OO concepts. Python is designed to be used interpretively.

More information

>>> print( X ) [0,1,2,3] def mystery(l):??

>>> print( X ) [0,1,2,3] def mystery(l):?? REVIEW EXERCISES Problem 4 What is the output of the following script? Disclaimer. I cannot guarantee that the exercises of the final exam are going to look like this. Also, for the most part, the exercises

More information

CS 1110 Final Exam May 9th, 2013 SOLUTIONS

CS 1110 Final Exam May 9th, 2013 SOLUTIONS Last Name: UTION First Name: SOL Cornell NetID, all caps: SU1110 CS 1110 Final Exam May 9th, 2013 SOLUTIONS This 150-minute exam has 7 questions worth a total of 53 points. When permitted to begin, scan

More information

61A Lecture 3. Friday, September 5

61A Lecture 3. Friday, September 5 61A Lecture 3 Friday, September 5 Announcements There's plenty of room in live lecture if you want to come (but videos are still better) Please don't make noise outside of the previous lecture! Homework

More information

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 6

CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none. Student Number: # 1: / 6 CSC 209H1 S 2012 Midterm Test Duration 50 minutes Aids allowed: none Last Name: Student Number: First Name: Lecture Section: L0101 Instructor: Reid Do not turn this page until you have received the signal

More information

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. ICS 31 UC IRVINE FALL 2012 DAVID G. KAY YOUR NAME YOUR LAB: YOUR STUDENT ID (8 DIGITS) SECTION (1-10) YOUR UCINET ID TIME MWF AT: 8 10 12 2 4 6 TA S NAME Second Midterm You have 75 minutes (until the end

More information

CIS192 Python Programming

CIS192 Python Programming CIS192 Python Programming Data Types Joseph Cappadona University of Pennsylvania September 03, 2015 Joseph Cappadona (University of Pennsylvania) CIS 192 September 03, 2015 1 / 32 Outline 1 Data Types

More information

Python Evaluation Rules

Python Evaluation Rules Python Evaluation Rules UW CSE 160 https://courses.cs.washington.edu/courses/cse160/15sp/ Michael Ernst and Isaac Reynolds mernst@cs.washington.edu April 1, 2015 Contents 1 Introduction 2 1.1 The Structure

More information

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

UTORid: Comments are not required except where indicated, although they may help us mark your answers. CSC 121H1 S 2018 Quiz 2 (Version B) March 19, 2018 Duration 35 minutes Aids allowed: none Last Name: Lecture Section: Instructor: UTORid: First Name: L0101 (MWF12) Mark Kazakevich Do not turn this page

More information

Midterm I Practice Problems

Midterm I Practice Problems 15-112 Midterm I Practice Problems Name: Section: andrewid: This PRACTICE midterm is not meant to be a perfect representation of the upcoming midterm! You are responsible for knowing all material covered

More information