# Overview of List Syntax

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Lists and Sequences

2 Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 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 to False (3 not in x) Assign 5 to element 2 and 4 to element x[k] = 2 * x[0] x[k 2] = 6 Assign -8 to x[3] and 6 to x[1] k 3

3 Lists vs. Tuples vs. Strings Creation x = [a1, a2, a3, ] Can contain anything len(x) is length Supports slicing Example: x[1:2] x[i] is anelement Can concatenate y = x + [1, 2] Makes a new list Is mutable x.append(5) Creation x = (a1, a2, a3, ) Can contain anything len(x) is length Supports slicing Example: x[1:2] x[i] is anelement Can concatenate y = x + (1, 2) Makes a new tuple Is not mutable Creation x = 'Hello' Only contains chars len(x) is length Supports slicing Example: x[1:2] x[i] is asubstring Can concatenate y = x + ' World' Makes a new string Is not mutable

4 Lists vs. Tuples vs. Strings Creation x = [a1, a2, a3, ] Can contain anything len(x) is length Supports slicing Example: x[1:2] x[i] is anelement Can concatenate y = x + [1, 2] Makes a new list Is mutable x.append(5) Creation Did x = (a1, a2, a3, s ) emester, not use this x b = u semester ' t H w ell o o r but works ' k Can contain anyth a in lm almost g ost lik like O e nl l lists y is c t o s do n d ta oiṅschars len(x) is length len(x) is length Supports slicing Supports slicing Example: x[1:2] Example: x[1:2] x[i] is anelement x[i] is asubstring Can Can concatenate concatenate y = y = x + ' World' x + (1, 2) Makes a Makes a new string new tuple Is not mutable Is not mutable

5 Quick for loop review Basic Structure: for <placeholder variable> in <list to loop through>: do something... Two general forms: thelist = [ a, b, c, d ] for foo in thelist: print foo Loops through the elements of thelist thelist = [ a, b, c, d ] for index in range(len(thelist)): print thelist[index] Loops through the indicies of thelist Think about what range really returns! range(4) >> [0,1,2,3] range(1) >> [0]

6 Modified Question 4 from Fall 2011 Each elements in the list scores contains the number of students who received score i on a test. For example, if 30 students got 85, then scores[85] is 30.Write the body of function histogram, which returns a histogram as a list of strings. (You need not write loop invariants.) For example, if scores = [7, 0, 4, 3, 2, 0, ] then the first elementsof the resulting string list are: '00 *******' '01 ' '02 ****' '03 ***' '04 *' '05 '

7 Modified Question 4 from Fall 2011 def histogram(scores): """Return a list of Strings (call it s) in which each s[i] contains: (1) i, as a two-digit integer (with leading zeros if necessary) (2) a blank, (3) n asterisks '*', where n is scores[i]. Precondition: scores is a list of nonnegative integers, len(scores) < 100""" # IMPLEMENT ME

8 Modified Question 4 from Fall 2011 def histogram(scores): """Return a list of Strings (call it s) in which each s[i] contains: (1) i, as a two-digit integer (with leading zeros if necessary) (2) a blank, (3) n asterisks '*', where n is scores[i]. Precondition: scores is a list of nonnegative integers, len(scores) < 100""" s = [] # List to contain the result. for i in range(len(scores)): if scores[i] < 10: else: row = str(scores[i]) + row = 0 + str(scores[i]) + for n in range(scores[i]): row = row + * s.append(row) return s # Need the value i, not the elements of scores # Add a 0 for double digits # Append scores[i] number of asterisks

9 Overview of Two-Dimensional Lists Access value at row 3, col 2: d[3][2] Assign value at row 3, col 2: d[3][2] = 8 An odd symmetry Number of rows of d: Number of cols in row r of d: len(d) len(d[r]) d

10 How Multidimensional Lists are Stored b = [[9, 6, 4], [5, 7, 7]] b b holds name of a one-dimensional list Has len(b) elements Its elements are (the names of) 1D lists b[i] holds the name of a one-dimensional list (of ints) Has len(b[i]) elements

11 Modified Question 4 from Fall 2010 Recall drawing GRectangles in A7. Write method placesquares, whose requirements appear below. It draws square bricks as shown to the right and returns them as a 2d list of GRectangle def placesquares(self, m): """Create a list of m x m squares (GRectangle), as specified below, adding the squares to the GUI, and return the list.""" Method Requirements: There are m columns and rows of squares; precondition: 0 < m. Each square has side length BRICK_SIDE; there is no space between them. The bottom-left square is at the bottom-left corner (0,0) of the GUI. Squares in columns and rows 0 and m-1 have color colormodel.pink Inner squares have checkerboard pattern of colormodel.red and colormodel.green, as shown (bottom-left one is green; one next to it, red).

12 Modified Question 4 from Fall 2010 Recall drawing GRectangles in A7. Write method placesquares, whose requirements appear below. It draws square bricks as shown to the right and returns them as a 2d list of GRectangle def placesquares(self, m): """Create a list of m x m squares (GRectangle), as specified on last slide, adding them to the GUI, and return the list.""" API Reminders: GRectangle has attributes pos (a 2 element tuple), size (a 2 element tuple), fillcolor, and linecolor You construct a GRectangle with keyword arguments: GRectangle(pos=(0,0),size=(10,10)) You add to the GUI with self.view.add( )

13 def placesquares(self, m): """Place the m x m Bricks, as requested on the exam and return the list""" bricks = []; r = 0 while r < m: row = []; c = 0 while c < m: # Make a new list to represent the whole grid # Place col c of bricks # Make a new list to represent rows color = colormodel.red if r == 0 or r == m-1 or c == 0 or c == m-1: color = colormodel.pink elif r+c % 2 == 0: color = colormodel.green brick=grectangle(pos=(r*brick_side,c*brick_side), fillcolor=color size=(brick_side,brick_side), linecolor=color) row.append(brick) self.view.add(brick) c = c+1 bricks.append(row) r = r+1 return bricks

14 Ragged Lists: Rows w/ Different Length b = [[17,13,19],[28,95]] b To create a ragged list Create b as an empty list (b =[]) Create each row as a list (r1 = [17,13,19]; r2 = [28,95]) Append lists to b (b.append(r1); b.append(r2))

15 Modified Question 4 from Fall 2011 Someone messed up a method to create certain arrays for us. For example (and this is only an example), they produced the array: instead of the array Thus, they put the last value of each row at the beginning instead of the end. Write a procedure that fixes this by rotating each row one position to the left; each element is moved one position earlier, and the first element is placed in the last position. Do not use recursion. DO NOT RETURN A VALUE. def rotate(b): """Rotate each row one position to the left, as explained above. Precondition: b is a list, might be ragged, and each row has >= 1 value"""

16 Modified Question 4 from Fall 2011 def rotate(b): """Rotate each row one position to the left, as explained on the previous slide. Precondition: b is a list, might be ragged, and each row has >= 1 value""" # invariant: rows 0..r 1 of b have been rotated r = 0 while r < len(b): first = b[r][0] # Rotate row r one position to the left; # inv: b[r][1..c 1] moved to b[r][0..c 2] c = 1 while c < len(b[r]) b[r][c-1]= b[r][c]; c= c+1 # post: b[r][1..] has been moved to b[r][0..] b[r][len(b[r]) 1]= first r = r+1 # post: rows 0..b.length 1 of b has been rotated

17 Dictionaries

18 Overview of Dictionary Syntax Creation d = dict() d = {} Insertion d[ new_key ] = new_value Modification d[ new_key ] = even_newer_value These two do the exact same thing! Creates an empty dictionary Adds new_value to d with the key of new_key Changes the value at new_key to even_newer_value Note: Insertion and Modification has the same syntax! Whether it modifies or not depends on if the key is already in the dictionary

19 Overview of Dictionary Syntax Creation d = dict() d = {} Insertion Modification Search d[ new_key ] = new_value d[ new_key ] = even_newer_value Deletion These two do the exact same thing! Creates an empty dictionary new_key in d >> returns True random_key in d >> returns False del d[ new_key ] Adds new_value to d with the key of new_key Deletes key-value pair: new_key is removed along with its value, even_newer_value Changes the value at new_key to even_newer_value Use the in keyword to check if a key is in the dictionary

20 Histograms Revisited (Dictionaries) def histogram(scores): """Return a histogram where the key value pair is: (score, number of occurrences) so that every score in scores is represented. If there a score is not in scores, then it does not need to be reflected in the dictionary with (score, 0). Precondition: scores is a list of nonnegative integers, len(scores) < 100""" # IMPLEMENT ME

21 Histograms Revisited (Dictionaries) def histogram(scores): """Return a histogram where the key value pair is: (score, number of occurrences) so that every score in scores is represented. If there a score is not in scores, then it does not need to be reflected in the dictionary with (score, 0). Precondition: scores is a list of nonnegative integers, len(scores) < 100"" histogram = dict() # Could have also written histogram = {} for score in scores: if score in histogram: else: histogram[score] += 1 histogram[score] = 1 return histogram # Check if this score is already in histogram

22 Histograms Revisited (Dictionaries) def histogram(scores): """Return a histogram where the key value pair is: (score, number of occurrences) so that every score in scores is represented. If there a score is not in scores, then it does not need to be reflected in the dictionary with (score, 0). Precondition: scores is a list of nonnegative integers, len(scores) < 100"" histogram = dict() # Could have also written histogram = {} for score in scores: if score in histogram: else: histogram[score] += 1 histogram[score] = 1 return histogram # Check if this score is already in histogram Very common idiom. Make sure you re familiar with it!

23 Python Basics

24 Basic Types Strings (str) Literals surrounded in quotes: Hello World! Booleans (bool) Two possible values: True or False Integers (int) Represents whole numbers: -1, 0, 1, 2, 3 Floats (float) Represents decimals: -0.1, , ,

25 Booleans (bool) Represents logical statements! Operators: not, and, or not b: True if b is false and False if b is true (negation) a and b: True if both a and b are true and False otherwise. a or b: True if a is true or b is true and False otherwise. Often are results of comparisons: Order comparison: a < b; a <=b; a >= b; a > b Equality comparison: a == b; a!= b Short Circuiting: (False and x / 0) vs (x / 0 and False) (True or x / 0) vs (x / 0 or True)

26 Strings (str) Used to represent text. Anything surrounded in either single quotes or double quotes is a string. Operators: + (concatenation) Hello + World! >> Hello World! Don t forget about string methods! A few common ones: find() and index(); know the difference and what the second optional argument does count() split() join() String indexing and splicing: You access specific indexes using s[i] where s is the str and i is an int Splice substrings using s[i:j]. i is inclusive while j is exclusive

27 If-statements Basic Structure: if <boolean expression>: do something else: do something This lets you control the flow of your code, directing it down branches depending on certain variables! Common style problem: if x == True: # Think about what the type of x is! do something else: do something

28 Questions

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

### Mini-Lecture 16. Nested Lists

Mini-Lecture 16 Nested Lists Nested Lists Lists can hold any object Lists are themselves objects Therefore lists can hold other lists! a = [2, 1] b = [3, 1] c = [1, 4, b] x = [1, a, c, 5] x[1] x[2] x[2][2]

### Lecture 14. Nested Lists and Dictionaries

Lecture 14 Nested Lists and Dictionaries Announcements for This Lecture Readings Today: Chapter 11 Next Week: Sec. 5.8-5.10 Prelim, Oct 12 th 7:30-9:00 Material up to TUESDAY Study guide is posted Review

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

CS 1110 Final, December 17th, 2014 This 150-minute exam has 8 questions 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

### Last Name: First: Netid: Section. CS 1110 Final, December 17th, 2014

CS 0 Final, December 7th, 204 SOLUTION This 50-minute exam has 8 questions worth a total of 00 points. Scan the whole test before starting. Budget your time wisely. Use the back of the pages if you need

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

CS 1110 Final, December 8th, 2016 This 150-minute exam has 8 questions 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

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

CS 1110 Final, December 8th, 2016 This 150-minute exam has 8 questions 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

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

CS 1110 Final, December 8th, 2016 This 150-minute exam has 8 questions 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

### PREPARING FOR PRELIM 1

PREPARING FOR PRELIM 1 CS 1110: FALL 2012 This handout explains what you have to know for the first prelim. There will be a review session with detailed examples to help you study. To prepare for the prelim,

### Intro. Scheme Basics. scm> 5 5. scm>

Intro Let s take some time to talk about LISP. It stands for LISt Processing a way of coding using only lists! It sounds pretty radical, and it is. There are lots of cool things to know about LISP; if

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

### Part III Appendices 165

Part III Appendices 165 Appendix A Technical Instructions Learning Outcomes This material will help you learn how to use the software you need to do your work in this course. You won t be tested on it.

### CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

CS 133 - Introduction to Computational and Data Science Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 Introduction to Python II In the previous class, you have

### Types, lists & functions

Week 2 Types, lists & functions Data types If you want to write a program that allows the user to input something, you can use the command input: name = input (" What is your name? ") print (" Hello "+

### GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

GIS 4653/5653: Spatial Programming and GIS More Python: Statements, Types, Functions, Modules, Classes Statement Syntax The if-elif-else statement Indentation and and colons are important Parentheses and

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

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

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

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

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

### ENGR 101 Engineering Design Workshop

ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as

### \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

### CS 1110 Prelim 2 November 13th, 2014

CS 1110 Prelim 2 November 13th, 2014 This 90-minute exam has 5 questions 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

### CS 1110 Prelim 2 November 14th, 2013

CS 1110 Prelim 2 November 14th, 2013 This 90-minute exam has 6 questions 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

### Programming to Python

Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the

### (f) d={ alchemist :( a, t ), shaman : ( s, n ), wizard : ( w, z )} d[ shaman ][1]

CSCI1101 Final Exam December 18, 2018 Solutions 1. Determine the value and type of each of the expressions below. If the question has two lines, assume that the statement in the first line is executed,

### Comp Exam 1 Overview.

Comp 170-400 Exam 1 Overview. Resources During the Exam The exam will be closed book, no calculators or computers, except as a word processor. In particular no Python interpreter running in a browser or

### Babu Madhav Institute of Information Technology, UTU 2015

Five years Integrated M.Sc.(IT)(Semester 5) Question Bank 060010502:Programming in Python Unit-1:Introduction To Python Q-1 Answer the following Questions in short. 1. Which operator is used for slicing?

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

### Arrays and Strings

Arrays and Strings 02-201 Arrays Recall: Fibonacci() and Arrays 1 1 2 3 5 8 13 21 34 55 a Fibonacci(n) a ß array of length n a[1] ß 1 a[2] ß 1 for i ß 3 to n a[i] ß a[i-1] + a[i-2] return a Declaring Arrays

### CS 1110 Prelim 2 April 22, 2014

CS 1110 Prelim 2 April 22, 2014 This 90-minute exam has 6 questions worth a total of 46 points. When permitted to begin, scan the whole test before starting. Budget your time wisely. Use the back of the

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

Python review CS 234 Naomi Nishimura The sections below indicate Python material, the degree to which it will be used in the course, and various resources you can use to review the material. You are not

### Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02

Mobile Computing Professor Pushpendra Singh Indraprastha Institute of Information Technology Delhi Java Basics Lecture 02 Hello, in this lecture we will learn about some fundamentals concepts of java.

### Computer Sciences 368 Scripting for CHTC Day 3: Collections Suggested reading: Learning Python

Day 3: Collections Suggested reading: Learning Python (3rd Ed.) Chapter 8: Lists and Dictionaries Chapter 9: Tuples, Files, and Everything Else Chapter 13: while and for Loops 1 Turn In Homework 2 Homework

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

### 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)

### Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

### CS 1110 Prelim 1 October 4th, 2012

CS 1110 Prelim 1 October 4th, 01 This 90-minute exam has 6 questions 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

### Exam 1 Format, Concepts, What you should be able to do, and Sample Problems

CSSE 120 Introduction to Software Development Exam 1 Format, Concepts, What you should be able to do, and Sample Problems Page 1 of 6 Format: The exam will have two sections: Part 1: Paper-and-Pencil o

### CPSC 217 Midterm (Python 3 version)

CPSC 217 Midterm (Python 3 version) Duration: 60 minutes 7 March 2011 This exam has 81 questions and 14 pages. This exam is closed book. No notes, books, calculators or electronic devices, or other assistance

### DaMPL. Language Reference Manual. Henrique Grando

DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4

### Worksheet 6: Basic Methods Methods The Format Method Formatting Floats Formatting Different Types Formatting Keywords

Worksheet 1: Introductory Exercises Turtle Programming Calculations The Print Function Comments Syntax Semantics Strings Concatenation Quotation Marks Types Variables Restrictions on Variable Names Long

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

### CS2304: Python for Java Programmers. CS2304: Sequences and Collections

CS2304: Sequences and Collections Sequences In Python A sequence type in python supports: The in membership operator. The len() function. Slicing like we saw with strings, s[1:3]. And is iterable (for

### CS Prelim 2 Review Fall 2018

CS 1110 Prelim 2 Review Fall 2018 Exam Info Prelim 1: Thursday, November 8th Last name L P at 5:15 6:45 in Uris G01 Last name Q Z at 5:15 6:45 in Statler Aud. Last name A D at 7:30 9:00 in Uris G01 Last

### ECS15, Lecture 14. Reminder: how to learn Python. Today is the final day to request a regrade of the midterm. Topic 4: Programming in Python, cont.

ECS15, Lecture 14 Today is the final day to request a regrade of the midterm Topic 4: Programming in Python, cont. Turn in a short cover letter explaining the issue. Reminder: how to learn Python Type

### Array. Prepared By - Rifat Shahriyar

Java More Details Array 2 Arrays A group of variables containing values that all have the same type Arrays are fixed length entities In Java, arrays are objects, so they are considered reference types

### 2. Explain the difference between read(), readline(), and readlines(). Give an example of when you might use each.

CMSC 0 Fall 0 Name Final Review Worksheet This worksheet is NOT guaranteed to cover every topic you might see on the exam. It is provided to you as a courtesy, as additional practice problems to help you

### CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types. COMP-202 Unit 6: Arrays

CONTENTS: Array Usage Multi-Dimensional Arrays Reference Types COMP-202 Unit 6: Arrays Introduction (1) Suppose you want to write a program that asks the user to enter the numeric final grades of 350 COMP-202

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

### Control Structures. Lecture 4 COP 3014 Fall September 18, 2017

Control Structures Lecture 4 COP 3014 Fall 2017 September 18, 2017 Control Flow Control flow refers to the specification of the order in which the individual statements, instructions or function calls

### Slicing. Open pizza_slicer.py

Slicing and Tuples Slicing Open pizza_slicer.py Indexing a string is a great way of getting to a single value in a string However, what if you want to use a section of a string Like the middle name of

### Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

Input, Processing and Output Bonita Sharif 1 Review A program is a set of instructions a computer follows to perform a task The CPU is responsible for running and executing programs A set of instructions

### CS1 Lecture 3 Jan. 18, 2019

CS1 Lecture 3 Jan. 18, 2019 Office hours for Prof. Cremer and for TAs have been posted. Locations will change check class website regularly First homework assignment will be available Monday evening, due

### CS 1110 Prelim 1 October 17th, 2013

CS 1110 Prelim 1 October 17th, 2013 This 90-minute exam has 6 questions 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

### CS1 Lecture 3 Jan. 22, 2018

CS1 Lecture 3 Jan. 22, 2018 Office hours for me and for TAs have been posted, locations will change check class website regularly First homework available, due Mon., 9:00am. Discussion sections tomorrow

### Script language: Python Data structures

Script language: Python Data structures Cédric Saule Technische Fakultät Universität Bielefeld 3. Februar 2015 Immutable vs. Mutable Previously known types: int and string. Both are Immutable but what

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

### CS115 - Module 9 - filter, map, and friends

Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Intermezzo 3 (Section 18); Sections 19-23. Abstraction abstraction, n. 3a.... The process of isolating properties or

### Lists, loops and decisions

Caltech/LEAD Summer 2012 Computer Science Lecture 4: July 11, 2012 Lists, loops and decisions Lists Today Looping with the for statement Making decisions with the if statement Lists A list is a sequence

### GE PROBLEM SOVING AND PYTHON PROGRAMMING. Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING

GE8151 - PROBLEM SOVING AND PYTHON PROGRAMMING Question Bank UNIT 1 - ALGORITHMIC PROBLEM SOLVING 1) Define Computer 2) Define algorithm 3) What are the two phases in algorithmic problem solving? 4) Why

### Teaching London Computing

Teaching London Computing A Level Computer Science Topic 3: Advanced Programming in Python William Marsh School of Electronic Engineering and Computer Science Queen Mary University of London Aims Further

### CS Exam 2 Name: Your Grading TA: This exam has 7 pages including the title page. Please check to make sure all pages are included.

CS1301 - Exam 2 Name: Your Grading TA: Instructions: Please write clearly. What I cannot read, I will not grade. Show all your work in detail. I give partial credit. This exam has 7 pages including the

### [CHAPTER] 1 INTRODUCTION 1

FM_TOC C7817 47493 1/28/11 9:29 AM Page iii Table of Contents [CHAPTER] 1 INTRODUCTION 1 1.1 Two Fundamental Ideas of Computer Science: Algorithms and Information Processing...2 1.1.1 Algorithms...2 1.1.2

### Visualize ComplexCities

Introduction to Python Chair of Information Architecture ETH Zürich February 22, 2013 First Steps Python Basics Conditionals Statements Loops User Input Functions Programming? Programming is the interaction

### LISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University

LISTS WITH PYTHON José M. Garrido Department of Computer Science May 2015 College of Computing and Software Engineering Kennesaw State University c 2015, J. M. Garrido Lists with Python 2 Lists with Python

### egrapher Language Reference Manual

egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

### Loops and Conditionals. HORT Lecture 11 Instructor: Kranthi Varala

Loops and Conditionals HORT 59000 Lecture 11 Instructor: Kranthi Varala Relational Operators These operators compare the value of two expressions and returns a Boolean value. Beware of comparing across

### Python for Non-programmers

Python for Non-programmers A Gentle Introduction 2 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013

### Lesson 4: Type Conversion, Mutability, Sequence Indexing. Fundamentals of Text Processing for Linguists Na-Rae Han

Lesson 4: Type Conversion, Mutability, Sequence Indexing Fundamentals of Text Processing for Linguists Na-Rae Han Objectives Python data types Mutable vs. immutable object types How variable assignment

### CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

CS 133 - Introduction to Computational and Data Science Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 Introduction to Python II In the previous class, you have

### Lecture 10: Lists and Sequences

http://www.cs.cornell.edu/courses/cs/8sp Lecture : Lists and Sequences (Sections.-.,.4-.6,.8-.) CS Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Gries, L. Lee, S. Marschner, C. Van

### COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts Ullrich Hustadt Department of Computer Science School of Electrical Engineering, Electronics, and Computer Science University of Liverpool Contents

### CS 1301 Exam 2 Fall 2010

CS 1301 Exam 2 Fall 2010 Name : Grading TA: Devices: If your cell phone, pager, PDA, beeper, ipod, or similar item goes off during the exam, you will lose 10 points on this exam. Turn all such devices

### 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:

### Introduction to Python

Introduction to Python EECS 4415 Big Data Systems Tilemachos Pechlivanoglou tipech@eecs.yorku.ca 2 Background Why Python? "Scripting language" Very easy to learn Interactive front-end for C/C++ code Object-oriented

### About the Final. Saturday, 7-10pm in Science Center 101. Closed book, closed notes. Not on the final: graphics, file I/O, vim, unix

CS 21 Final Review About the Final Saturday, 7-10pm in Science Center 101 Closed book, closed notes Not on the final: graphics, file I/O, vim, unix Expect Questions That Ask You To: Evaluate Python expressions

### CS 1301 Exam 1 Fall 2010

CS 1301 Exam 1 Fall 2010 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam in

### CIS192: Python Programming

CIS192: Python Programming Introduction Harry Smith University of Pennsylvania January 18, 2017 Harry Smith (University of Pennsylvania) CIS 192 Lecture 1 January 18, 2017 1 / 34 Outline 1 Logistics Rooms

### Issue with Implementing PrimeSieve() in Go

Slices 02-201 Issue with Implementing PrimeSieve() in Go func PrimeSieve(n int) [n+1]bool { var iscomposite [n+1]bool //ERROR! biggestprime := 2 for biggestprime < n for i:=2; i

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

### Topic 7: Lists, Dictionaries and Strings

Topic 7: Lists, Dictionaries and Strings The human animal differs from the lesser primates in his passion for lists of Ten Best H. Allen Smith 1 Textbook Strongly Recommended Exercises The Python Workbook:

### Scheme as implemented by Racket

Scheme as implemented by Racket (Simple view:) Racket is a version of Scheme. (Full view:) Racket is a platform for implementing and using many languages, and Scheme is one of those that come out of the

### CS115 - Module 8 - Binary trees

Fall 2017 Reminder: if you have not already, ensure you: Read How to Design Programs, Section 14. Binary arithmetic expressions Operators such as +,,, and take two arguments, so we call them binary operators.

### NOTE: All references to Python on this exam mean Python 3, so you should answer accordingly.

Name: (as it would appear on official course roster) Umail address: @umail.ucsb.edu EXAM: : Midterm Exam ready? date points true Tue 04/24 03:30PM 100 1 You may not collaborate on this exam with anyone.

### 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;

### TUPLES AND RECURSIVE LISTS 5

TUPLES AND RECURSIVE LISTS 5 COMPUTER SCIENCE 61A July 3, 2012 1 Sequences From the Pig project, we discovered the utility of having structures that contain multiple values. Today, we are going to cover

### CS 1110 Final Exam Solutions May 15th, 2014

Last Name: First Name: Cornell NetID, all caps: The Important First Question: CS 1110 Final Exam Solutions May 15th, 2014 1. [2 points] When allowed to begin, write your last name, first name, and Cornell

### EXAM Computer Science 1 Part 1

Maastricht University Faculty of Humanities and Science Department of Knowledge Engineering EXAM Computer Science 1 Part 1 Block 1.1: Computer Science 1 Code: KEN1120 Examiner: Kurt Driessens Date: Januari

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

### CS 11 python track: lecture 3. n Today: Useful coding idioms

CS 11 python track: lecture 3 Today: Useful coding idioms Useful coding idioms "Idiom" Standard ways of accomplishing a common task Using standard idioms won't make your code more correct, but more concise

### A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

### CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts

CMPSCI 119 Fall 2018 Wednesday, November 14, 2018 Midterm #2 Solution Key Professor William T. Verts 25 Points What is the value of each expression below? Answer any 25; answer more for extra credit.

### CS 2316 Exam 1 Spring 2014

CS 2316 Exam 1 Spring 2014 Name : Grading TA: Integrity: By taking this exam, you pledge that this is your work and you have neither given nor received inappropriate help during the taking of this exam

### THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September COMP1730 / COMP6730 Programming for Scientists

THE AUSTRALIAN NATIONAL UNIVERSITY Mid Semester Examination September 2016 COMP1730 / COMP6730 Programming for Scientists Study Period: 15 minutes Time Allowed: 2 hours Permitted Materials: One A4 page

### CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

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