Announcements 15-112 Fundamentals of Programming What are we doing today?

Please download to get full document.

View again

of 4
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Information Report
Category:

Math & Engineering

Published:

Views: 3 | Pages: 4

Extension: PDF | Download: 0

Share
Related documents
Description
9/12/2013 Announcements Read pages 74 – 77 15-112 Fundamentals of Assignment 2 is due Tuesday at 11:59pm Programming September 8th , 2013 What are we…
Transcript
9/12/2013 Announcements Read pages 74 – 77 15-112 Fundamentals of Assignment 2 is due Tuesday at 11:59pm Programming September 8th , 2013 What are we doing today? Some common problems Some common errors What in the world does return do? Lists Functions, variables, input parameters, List functions raw_input, what is all this!!!! Defining functions vs calling functions How do I draw the square and circle? I am struggling in the course and we just started – what should I do? 1 9/12/2013 Lists – Lets start with the “why” Lists as sequence of values Given a sequence of numbers, how do Variables can hold one value at a time you find the minimum value? Lists can hold a number of different values How do you find: max, sum, average? How do you find: How many numbers are above average? Create a list Creating Lists A simple list Combining two lists myList = [1, 4, 5, 8, 12] myList = [1, 4, 5, 8, 12] yourList = [3,7,4,9] An initialized list ourList = myList + yourList myList = [0] * 5  ourList would be [1, 4, 5, 8, 12, 3, 7, 4, 9] myList [0,0,0,0,0] Adding element to a list a = [0] * 5 b= 12 a = a + [b] a [0,0,0,0,0,12] 2 9/12/2013 Accessing Elements Modifying Elements a = [2, 3, 5, 7, 11, 13] a = [2, 3, 5, 7, 11, 13] print a[0] 2 [2, 3, 5, 7, 11, 13] print a[2] 5 print a print a[-1] 13 a[2] = 0 7 print a [2, 3, 0, 7, 11, 13] print a[-3] print a[0:2] [2,3] print a[1:4] [3, 5, 7] print a[1:6:2] [3, 7, 13] More List Operations Finding Elements Slicing a List Check for list membership: using “in” myList  [1, 4, 5, 200, 12] print myList[1:3] [4, 5] a = [ 2, 3, 5, 2, 6, 2, 2, 7 ] print a = , a print (2 in a) Assigning Value to a slice print (4 in a) myList[1:3] = [6,6,6,6] myList [1, 6, 6, 6, 6, 200, 12] 3 9/12/2013 Looping over Lists Exercise a = [ 2, 3, 5, 7 ] Write a function called isSubset, that takes two lists as input parameters. The function for item in a: should return True if all elements of first print item list are in second list. Try out each of the functions listed in the table on page 64 and understand their behavior. 4
Recommended
View more...
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks