mith College Computer Science Week 12 CSC111 Spring 2018 Dominique Thiébaut
|
|
- Henry Watts
- 6 years ago
- Views:
Transcription
1 mith College Computer Science Week 12 CSC111 Spring 2018 Dominique Thiébaut
2 Nice_Wrapping_Paper...
3 Polymorphism Dictionaries & Recursion
4 Polymorphism
5 Poly = Many Morph = Form, Shape
6 Poly = Many Morph = Form, Shape Image taken from
7 Poly = Many Morph = Form, Shape Speak() Image taken from
8 Poly = Many Morph = Form, Shape Speak() Image taken from
9 Poly = Many Morph = Form, Shape Speak() Image taken from
10 Poly = Many Morph = Form, Shape Polymorphism is the ability for a function, or method, to behave differently depending on which class it belongs to, or what type of parameter is given to it. Image taken from
11 Let's Code this!
12 animalstalk.py
13
14
15 Polymorphism Polymorphism Polymorphism
16 Overloading
17 Another Example of Polymorphism: the + operator
18 Another Example of Polymorphism: the + operator
19 Another Example of Polymorphism: the + operator Overloading
20 Abundant syntax brings more burden than help. Guido van Rossum
21 Abundant and del from not while syntax brings as elif global or with assert else if pass yield break except import print more burden class exec in raise continue finally is return than help. def for lambda try Guido van Rossum
22 Dictionaries
23 Review Lists dogs = [ Ralph, Blake, Fido, Rex, Milou ]
24 Review Lists dogs = [ Ralph, Blake, Fido, Rex, Milou ] Ralph Blake Fido Rex Milou dogs
25 Review Lists dogs = [ Ralph, Blake, Fido, Rex, Milou ] Ralph Blake Fido Rex Milou dogs Index Value
26 Dictionaries: Indexing Data by Name
27 "Apple" : 95, "Apricot" : 29, "Avocado" : 270, "Banana" : 95, What we d like:
28 "Apple" : 95, "Apricot" : 29, "Avocado" : 270, "Banana" : 95, What we d like: calories Apple Apricot Avocado Banana 95
29 "Apple" : 95, "Apricot" : 29, "Avocado" : 270, "Banana" : 95, What we d like: calories Apple Apricot Avocado Banana 95 Key Value
30 DICTIONARY Zelle, Section 11.7
31 Dictionaries Dictionaries are Data Structures The item used as an index is called the key The item associated with the key is the value A dictionary is a container, or a collection of (key, value) pairs Searching for a key in a dictionary is a very fast operation. searchlistanddictionary.py
32 Example
33 Example
34 Example
35 Example
36 Programming Example 1 How many calories in a smoothie? totalcalories.py
37 totalcalories.py
38 Programming Example 2 Adelyn@smith.edu MTH Adison@mtholyoke.edu ARH Aisha@smith.edu MTH Alana@smith.edu MTH Aleena@smith.edu CSC... Taniya@smith.edu SPN Tara@smith.edu CSC Tatum@smith.edu MTH Tianna@smith.edu ARH Tiara@smith.edu CSC Tori@smith.edu MTH Violet@smith.edu ARH Wendy@smith.edu ECO Yareli@smith.edu FRN Yaritza@smith.edu ARH Yuliana@smith.edu ECO smithy@umass.edu ARH
39 Programming Example 2 Adelyn@smith.edu MTH Adison@mtholyoke.edu ARH Aisha@smith.edu MTH Alana@smith.edu MTH Aleena@smith.edu CSC... Taniya@smith.edu SPN Tara@smith.edu CSC Tatum@smith.edu MTH Tianna@smith.edu ARH Tiara@smith.edu CSC Tori@smith.edu MTH Violet@smith.edu ARH Wendy@smith.edu ECO Yareli@smith.edu FRN Yaritza@smith.edu ARH Yuliana@smith.edu ECO smithy@umass.edu ARH countmajors.py
40 Programming Example 2 Adelyn@smith.edu MTH Adison@mtholyoke.edu ARH Aisha@smith.edu MTH Alana@smith.edu MTH Aleena@smith.edu CSC... Taniya@smith.edu SPN Tara@smith.edu CSC Tatum@smith.edu MTH Tianna@smith.edu ARH Tiara@smith.edu CSC Tori@smith.edu MTH Violet@smith.edu ARH Wendy@smith.edu ECO Yareli@smith.edu FRN Yaritza@smith.edu ARH Yuliana@smith.edu ECO smithy@umass.edu ARH countmajors.py
41 Programming Example 3 CREDIT: MOVIESTORE/REX/SHUTTERSTOCK Street Car Named Desire
42
43 streetcarwithdictionaries.py
44
45
46
47 Recursion
48 Tough problems, simple solutions Recursion & Recursive Functions Finding the Largest in a List Finding the Smallest in a List Factorial Traversing a Maze Fractal Trees Towers of Hanoi
49
50 A B C
51 A B A C B C A B C A A B C
52 Some Problems Can be Solved With Little Coding using Special Programming Techniques
53 Recursive Functions
54 Solving Problems Recursively: Class Exercises Largest in a list Smallest in a list Find item in a list Wrap text Factorial Draw a Chessboard
55 bunch of bananas Find the largest in a list
56 bunch of bananas Find the largest in a list (Lazy, but clever. Has lots of friends)
57 Python
58 Python Stopping Condition Recursive Step
59 Animation
60 Animation
61 Animation
62 Animation
63 Animation
64 Animation
65 Animation
66 Animation
67 Animation
68 120 Animation
69 Once Again! With this Simplified Version
70 Once Again! With this Simplified Version Stopping Condintion Recursive Step
71 Animation
72 Animation
73 Animation
74 Animation
75 Animation
76 Animation
77 Animation
78 Animation
79 Animation
80 Animation
81 120 Animation
82 Minions: Can you tell me if there s a banana that weighs 118 grams?
83 Minions: Here's a bunch of bananas. Return to me the smallest and the largest.
84 Tough problems, simple solutions Recursive Functions Finding the Largest in a List Finding the Smallest in a List Factorial Traversing a Maze Towers of Hanoi
85 Standard CS Example: Factorial
86 Factorial given: positive integer n wanted: factorial of n = n!
87 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise
88 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise
89 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise 5! = 5 x 4!
90 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise 5! = 5 x 4! = 5 x 4 x 3!
91 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise 5! = 5 x 4! = 5 x 4 x 3! = 5 x 4 x 3 x 2!
92 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise 5! = 5 x 4! = 5 x 4 x 3! = 5 x 4 x 3 x 2! = 5 x 4 x 3 x 2 x 1!
93 Factorial given: positive integer n wanted: factorial of n = n! = 1 if n == 1 {n x (n-1)! otherwise 5! = 5 x 4! = 5 x 4 x 3! = 5 x 4 x 3 x 2! = 5 x 4 x 3 x 2 x 1! = 5 x 4 x 3 x 2 x 1 = 120
94 Demo Time!
95 Under the Hood: Animated Python Functions
96 1 2 3 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y )
97 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y:
98 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: f1: (return to 6) a: temp:
99 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: f1: (return to 6) a: 4 temp:
100 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: f1: (return to 6) a: 4 temp: 8
101 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: f1: 8(return to 6) a: 4 temp: 8
102 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: 8 f1: 8(return to 6) a: 4 temp: 8
103 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: 8
104 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: 8
105 def f1( a ): temp = a*2 return temp x = 4 y = f1( x ) print( y ) x: 4 y: 8 8
106 We stopped here last time
107 Recursion: Factorial
108 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y:
109 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y:
110 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:
111 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4
112 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4
113 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4
114 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:
115 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4-1 fact: (ret. to 4) n:3
116 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3
117 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3
118 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3
119 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2
120 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2
121 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2
122 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2 fact: (ret. to 4) n:1
123 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2 fact: (ret. to 4) n:1
124 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2 fact: (ret. to 4) n:1
125 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2 fact:1 (ret. to 4) n:1
126 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2*1 fact:1 (ret. to 4) n:1
127 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact: (ret. to 4) n:2*1
128 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3 fact:2 (ret. to 4) n:2*1
129 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3*2 fact:2 (ret. to 4) n:2*1
130 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact: (ret. to 4) n:3*2
131 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4 fact:6 (ret. to 4) n:3*2
132 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact: (ret. to 7) n:4*6
133 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y: fact:24(ret. to 7) n:4*6
134 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y:24 fact:24(ret. to 7) n:4*6
135 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y:24
136 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y:24
137 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) x: 4 y:24 24
138 def fact( n ): if n<=1: return 1 return n*fact(n-1) x = 4 y = fact( x ) print( y ) 24
139 Minions: Can you tell me if there s a banana that weighs 118 grams?
140 Minions: Here's a bunch of bananas. Return to me the smallest and the largest.
141 We stopped here last time
mith College Computer Science Week 13 CSC111 Fall 2015 (Lab 12, Homework 12) Dominique Thiébaut
mith College Computer Science Week 13 CSC111 Fall 2015 (Lab 12, Homework 12) Dominique Thiébaut dthiebaut@smith.edu This Week: Two Concepts Lists of Lists Class Inheritance Lists of Lists (Chapter 11 Designing
More informationmith College Computer Science Week 13 CSC111 Spring 2018 Dominique Thiébaut
mith College Computer Science Week 13 CSC111 Spring 2018 Dominique Thiébaut dthiebaut@smith.edu Recursion Continued Visiting a Maze Start Exit How do we represent a maze in Python? mazetext = """ #########################...#
More informationmith College Computer Science CSC231 Assembly Week #13 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC21 Assembly Week #1 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu for n in 0 1 2 5 ; do echo "n =$n"./hw7b $n echo "" done Pascal Triangle n =0 n =1 1 n =2 1 0 1 1 n
More informationChapter 2 Writing Simple Programs
Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle (www.si182.com) Software Development Process Figure out the problem - for
More informationCSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output
CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2011 Python Python was developed
More informationJython. secondary. memory
2 Jython secondary memory Jython processor Jython (main) memory 3 Jython secondary memory Jython processor foo: if Jython a
More informationCSCE 110 Programming I
CSCE 110 Programming I Basics of Python (Part 1): Variables, Expressions, and Input/Output Dr. Tiffani L. Williams Department of Computer Science and Engineering Texas A&M University Spring 2013 Tiffani
More informationmith College Computer Science Week 10 CSC111 Spring 2015 Dominique Thiébaut
mith College Computer Science Week 10 CSC111 Spring 2015 Dominique Thiébaut dthiebaut@smith.edu Next Few Lectures Image Processing with Nested For-Loops Lists can be Used to Solve Many Problems (Chap.
More informationSI Networked Computing: Storage, Communication, and Processing, Winter 2009
University of Michigan Deep Blue deepblue.lib.umich.edu 2009-01 SI 502 - Networked Computing: Storage, Communication, and Processing, Winter 2009 Severance, Charles Severance, C. (2008, December 19). Networked
More informationCHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS
CHAPTER 2: Introduction to Python COMPUTER PROGRAMMING SKILLS 1439-1440 1 Outline 1. Introduction 2. Why Python? 3. Compiler and Interpreter 4. The first program 5. Comments and Docstrings 6. Python Indentations
More informationLecture 27. Lecture 27: Regular Expressions and Python Identifiers
Lecture 27 Lecture 27: Regular Expressions and Python Identifiers Python Syntax Python syntax makes very few restrictions on the ways that we can name our variables, functions, and classes. Variables names
More informationmith College Computer Science Lecture Notes CSC111 Week 7 Spring 2018 Dominique Thiébaut
mith College Computer Science Lecture Notes Week 7 Spring 2018 CSC111 Dominique Thiébaut dthiebaut@smith.edu Midterm Grades available later today (3/19/18) Outline A Second Look at Files Reading Files
More informationGE 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
More informationGetting Started with Python
Fundamentals of Programming (Python) Getting Started with Python Sina Sajadmanesh Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationPython 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
More informationShort, Unique and Mysterious
Short, Unique and Mysterious Q Why is the Programming Language named so? a Monty Python's Flying Circus "A t t h e t i m e w h e n h e b e g a n implementing Python, Guido van R o s s u m w a s a l s o
More informationThere are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)
I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications
More informationAbout Variables in Python F E B 1 1 T H
About Variables in Python F E B 1 1 T H Range of floating point numbers What is the largest floating point number in Python? Unfortunately, there is no sys.maxfloat. Here is an interesting way to find
More informationThere are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)
I. INTERACTIVE MODE VERSUS SCRIPT MODE There are two ways to use the python interpreter: interactive mode and script mode. 1. Interactive Mode (a) open a terminal shell (terminal emulator in Applications
More informationReview. 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
More informationmith College Computer Science CSC231 Assembly Week #12 Thanksgiving 2017 Dominique Thiébaut
mith College Computer Science CSC231 Assembly Week #12 Thanksgiving 2017 Dominique Thiébaut dthiebaut@smith.edu ;;; FUNCTION SIDE function: ebp ;save old ebp ebp, esp ;make ebp point ;to stack frame Summary
More informationENGR 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
More informationCSC 148 Lecture 3. Dynamic Typing, Scoping, and Namespaces. Recursion
CSC 148 Lecture 3 Dynamic Typing, Scoping, and Namespaces Recursion Announcements Python Ramp Up Session Monday June 1st, 1 5pm. BA3195 This will be a more detailed introduction to the Python language
More informationIntroduction to Python, Cplex and Gurobi
Introduction to Python, Cplex and Gurobi Introduction Python is a widely used, high level programming language designed by Guido van Rossum and released on 1991. Two stable releases: Python 2.7 Python
More informationmith College Computer Science CSC231-Assembly Week #1 Fall 2018 Dominique Thiébaut
mith College Computer Science CSC231-Assembly Week #1 Fall 2018 Dominique Thiébaut dthiebaut@smith.edu This Week Last name: A-N > Lab Monday, Off Wednesday Last name: M-Z > Off Monday, Lab Wednesday Plan
More informationTable of Contents EVALUATION COPY
Table of Contents Introduction... 1-2 A Brief History of Python... 1-3 Python Versions... 1-4 Installing Python... 1-5 Environment Variables... 1-6 Executing Python from the Command Line... 1-7 IDLE...
More informationBeyond programming. CS 199 Computer Science for Beginners Spring 2009 Lois Delcambre Week 5/12/2009 1
Beyond programming CS 199 Computer Science for Beginners Spring 2009 Lois Delcambre Week 5/12/2009 1 Introduction We ve covered: Python data types Python expressions Python statements We ve written approximately
More informationFundamentals of Programming (Python) Getting Started with Programming
Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science
More informationWhy Program? Computers want to be helpful... Programmers Anticipate Needs. Chapter 1. Computers are built for one purpose - to do things for us
Why Program? Chapter 1 Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/. Copyright 2010,
More informationmith College Computer Science Week 7 CSC111 Fall 2015 Dominique Thiébaut
mith College Computer Science Week 7 CSC111 Fall 2015 Dominique Thiébaut dthiebaut@smith.edu Dynamic Web Page Example IF Statements & Boolean Expression An Application: Generating Dynamic Web Pages Introduction
More informationSome material adapted from Upenn cmpe391 slides and other sources
Some material adapted from Upenn cmpe391 slides and other sources History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Understanding Reference Semantics
More informationWhat is an algorithm?
Announcements CS 142 Recursion Reminder: Program 3 due 2/18 by 11:55pm 2 Write a function that computes the factorial of a number using a loop (for or while loop is fine). Examples: factorial(5) returns
More informationToday. CISC101 Reminders & Notes. Searching in Python - Cont. Searching in Python. From last time
CISC101 Reminders & Notes Test 3 this week in tutorial USATs at the beginning of next lecture Please attend and fill out an evaluation School of Computing First Year Information Session Thursday, March
More informationThe float type and more on variables FEB 6 TH 2012
The float type and more on variables FEB 6 TH 2012 The float type Numbers with decimal points are easily represented in binary: 0.56 (in decimal) = 5/10 + 6/100 0.1011 (in binary) = ½+0/4 + 1/8 +1/16 The
More informationSenthil Kumaran S
Senthil Kumaran S http://www.stylesen.org/ Agenda History Basics Control Flow Functions Modules History What is Python? Python is a general purpose, object-oriented, high level, interpreted language Created
More informationPython BASICS. Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc.
Python BASICS Introduction to Python programming, basic concepts: formatting, naming conventions, variables, etc. Identikit First appeared in 1991 Designed by Guido van Rossum General purpose High level
More informationmith College Computer Science Week 9 CSC111 - Fall 2018 Dominique Thiébaut
mith College Computer Science Week 9 CSC111 - Fall 2018 Dominique Thiébaut dthiebaut@smith.edu Dealing with Exceptions (Chapter 7.4) Defining Classes (Chapter 10) # getinput: returns an integer larger
More informationBeyond Blocks: Python Session #1
Beyond Blocks: Session #1 CS10 Spring 2013 Thursday, April 30, 2013 Michael Ball Beyond Blocks : : Session #1 by Michael Ball adapted from Glenn Sugden is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike
More informationLab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han
Lab 1: Course Intro, Getting Started with Python IDLE Ling 1330/2330 Computational Linguistics Na-Rae Han Objectives Course Introduction http://www.pitt.edu/~naraehan/ling1330/index.html Student survey
More informationCS 61A Interpreters, Tail Calls, Macros, Streams, Iterators. Spring 2019 Guerrilla Section 5: April 20, Interpreters.
CS 61A Spring 2019 Guerrilla Section 5: April 20, 2019 1 Interpreters 1.1 Determine the number of calls to scheme eval and the number of calls to scheme apply for the following expressions. > (+ 1 2) 3
More informationRecursion CS GMU
Recursion CS 112 @ GMU Recursion 2 Recursion recursion: something defined in terms of itself. function recursion: when a function calls itself. Sometimes this happens directly, sometimes indirectly. direct:
More informationSelection Statement ( if )
Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 4 Selection Statement ( if ) Eng. Ibraheem Lubbad October 10, 2016 In this lab we will constructs program that allow
More informationTopics Applications Most Common Methods Serial Search Binary Search Search by Hashing (next lecture) Run-Time Analysis Average-time analysis Time anal
CSC212 Data Structure t Lecture 18 Searching Instructor: George Wolberg Department of Computer Science City College of New York @ George Wolberg, 2016 1 Topics Applications Most Common Methods Serial Search
More informationGetting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013
CSE 231, Rich Enbody Office Hours After class By appointment send an email 2 1 Project 1 Python arithmetic Do with pencil, paper and calculator first Idle Handin Help room 3 What is a Computer Program?
More informationmith College Computer Science CSC111 Week 8 Spring 2018 Dominique Thiébaut
mith College Computer Science CSC111 Week 8 Spring 2018 Dominique Thiébaut dthiebaut@smith.edu mith Hac Smith Hack Smi k Smith Hack Smith Ha ack Smith Hack Smith Hack Smit ack Smith Hack Smith Hack Smith
More information61A LECTURE 22 TAIL CALLS, ITERATORS. Steven Tang and Eric Tzeng July 30, 2013
61A LECTURE 22 TAIL CALLS, ITERATORS Steven Tang and Eric Tzeng July 30, 2013 Announcements Homework 12 due Thursday, not Monday. Take the time to get started on the project instead! Almost done with Scheme
More informationPYTHON PROGRAMMING. John M.Zelle. Wartburg College AN INTRODUCTION TO COMPUTER SCIENCE SECOND EDITION
PYTHON PROGRAMMING AN INTRODUCTION TO COMPUTER SCIENCE SECOND EDITION * John M.Zelle Wartburg College Franklin, Beedle & Associates Inc. * 22462 SW Washington Si 'efion 97140 * 503/625-4445 + www.fbeedle.com
More information2: Complexity and Recursion
2: Complexity and Recursion Today About CS1 Complexity Introduction Examples Homework 1 Solutions Project 1 2 CS1 Exam Problem 4: Another cipher No problem for most students Highest average score Want
More informationIntroduction to Problem Solving and Programming in Python.
Introduction to Problem Solving and Programming in Python http://cis-linux1.temple.edu/~tuf80213/courses/temple/cis1051/ Overview Types of errors Testing methods Debugging in Python 2 Errors An error in
More informationmith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Ben Fry on Processing... http://www.youtube.com/watch?&v=z-g-cwdnudu An Example Mouse 2D
More informationObroni Computer Club Dictionaries and more
Obroni Computer Club Dictionaries and more Joachim Breitner Oktober 10 țh 2006 Last week you suggested that I should be using less prepared slides and more demonstration of coding. So today, we ll try
More informationBasic Syntax - First Program 1
Python Basic Syntax Basic Syntax - First Program 1 All python files will have extension.py put the following source code in a test.py file. print "Hello, Python!";#hello world program run this program
More informationSTEAM Clown & Productions Copyright 2017 STEAM Clown. Page 1
What to add next time you are updating these slides Update slides to have more animation in the bullet lists Verify that each slide has stand alone speaker notes Page 1 Python 3 Running The Python Interpreter
More informationmith College Computer Science Week 8 CSC111 - Spring 2015 Dominique Thiébaut
mith College Computer Science Week 8 CSC111 - Spring 2015 Dominique Thiébaut dthiebaut@smith.edu Midterm Exams Returned Wed 3/26 1:00 p.m. FH356 ! Review Loops & Booleans (Chapter 8) For loops in context
More informationProgramming with Python
Programming with Python Dr Ben Dudson Department of Physics, University of York 21st January 2011 http://www-users.york.ac.uk/ bd512/teaching.shtml Dr Ben Dudson Introduction to Programming - Lecture 2
More informationMacros & Streams Spring 2018 Discussion 9: April 11, Macros
CS 61A Macros & Streams Spring 2018 Discussion 9: April 11, 2018 1 Macros So far, we ve mostly explored similarities between the Python and Scheme languages. For example, the Scheme list data structure
More informationmith College CSC 111 Introduction to Computer Science Spring 2018 Week 2 Dominique Thiébaut
mith College Computer Science CSC 111 Introduction to Computer Science Spring 2018 Week 2 Dominique Thiébaut dthiebaut@smith.edu Outline Moodle Access Piazza Homework partners Loops + range() Input Programming
More informationCSC148 winter stools, names, tracing week 5
1/18 CSC148 winter 2014 stools, names, tracing week 5 Danny Heap / Dustin Wehr heap@cs.toronto.edu / dustin.wehr@utoronto.ca BA4270 / SF4306D http://www.cdf.toronto.edu/~heap/148/f13/ February 5, 2014
More informationDelayed Expressions Fall 2017 Discussion 9: November 8, Iterables and Iterators. For Loops. Other Iterable Uses
CS 6A Delayed Expressions Fall 07 Discussion 9: November 8, 07 Iterables and Iterators An iterable is any container that can be processed sequentially. Examples include lists, tuples, strings, and dictionaries.
More informationModule 06. Topics: Iterative structure in Python Readings: ThinkP 7. CS116 Spring : Iteration
Module 06 Topics: Iterative structure in Python Readings: ThinkP 7 1 In Python, repetition can be recursive def count_down_rec(x): ''' Produces the list [x, x-1, x-2,..., 1,0] count_down:nat->(listof Nat)'''
More informationPROGRAMMING FUNDAMENTALS
PROGRAMMING FUNDAMENTALS VARIABLES, EXPRESSIONS AND STATEMENTS João Correia Lopes INESC TEC, FEUP 27 September 2018 FPRO/MIEIC/2018-19 27/09/2018 1 / 21 INTRODUCTION GOALS By the end of this class, the
More informationVariable 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 informationCSCA08 Winter Week 12: Exceptions & Testing. Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough
CSCA08 Winter 2018 Week 12: Exceptions & Testing Marzieh Ahmadzadeh, Brian Harrington University of Toronto Scarborough Administrative stuff We ll have a surprise for you: An extra exercise! You don t
More informationmith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Important Review Does the animation leave a trace? Are the moving objects move without a
More informationIterators & Generators
Iterators & Generators Sequences A sequence is something that you can: Index into Get the length of What are some examples of sequences? Sequences We ve been working with sequences all semester! Examples:
More informationHistory Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability
History Installing & Running Python Names & Assignment Sequences types: Lists, Tuples, and Strings Mutability Some material adapted from Upenn cmpe391 slides and other sources Invented in the Netherlands,
More informationWarmup: On paper, write a C++ function that takes a single int argument (n) and returns the product of all the integers between 1 and n.
Warmup: On paper, write a C++ function that takes a single int argument (n) and returns the product of all the integers between 1 and n. Use a for loop. (This is actually a useful function in science and
More informationTAIL RECURSION, SCOPE, AND PROJECT 4 11
TAIL RECURSION, SCOPE, AND PROJECT 4 11 COMPUTER SCIENCE 61A Noveber 12, 2012 1 Tail Recursion Today we will look at Tail Recursion and Tail Call Optimizations in Scheme, and how they relate to iteration
More informationAlgorithm. Building blocks of algorithm
UNIT I ALGORITHMIC PROBLEM SOLVING 9 Algorithms, building blocks of algorithms (statements, state, control flow, functions), notation (pseudo code, flow chart, programming language), algorithmic problem
More informationLists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, 2019 Solutions. 1 Sequences. Questions. lst = [1, 2, 3, 4, 5] lst[1:3]
CS 61A Lists, Mutability, ADTs, and Trees Spring 2019 Guerrilla Section 2: March 2, 2019 Solutions 1 Sequences Questions 1.1 What would Python display? lst = [1, 2, 3, 4, 5] lst[1:3] [2, 3] lst[0:len(lst)]
More informationTHE IF STATEMENT. The if statement is used to check a condition: if the condition is true, we run a block
THE IF STATEMENT The if statement is used to check a condition: if the condition is true, we run a block of statements (called the if-block), elsewe process another block of statements (called the else-block).
More informationCS150 - Sample Final
CS150 - Sample Final Name: Honor code: You may use the following material on this exam: The final exam cheat sheet which I have provided The matlab basics handout (without any additional notes) Up to two
More informationCS112 Spring 2012 Dr. Kinga Dobolyi. Exam 2. Do not open this exam until you are told. Read these instructions:
CS112 Spring 2012 Dr. Kinga Dobolyi Exam 2 Do not open this exam until you are told. Read these instructions: 1. This is a closed book exam. No calculators, notes, or other aids are allowed. If you have
More informationwww.thestudycampus.com Recursion Recursion is a process for solving problems by subdividing a larger problem into smaller cases of the problem itself and then solving the smaller, more trivial parts. Recursion
More informationSTATS 507 Data Analysis in Python. Lecture 0: Introduction and Administrivia
STATS 507 Data Analysis in Python Lecture 0: Introduction and Administrivia Data science has completely changed our world Course goals Establish a broad background in Python programming Prepare you for
More informationAl al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department
Al al-bayt University Prince Hussein Bin Abdullah College for Information Technology Computer Science Department 0901212 Python Programming 1 st Semester 2014/2015 Course Catalog This course introduces
More information15-110: Principles of Computing, Spring 2018
15-110: Principles of Computing, Spring 2018 Problem Set 5 (PS5) Due: Friday, February 23 by 2:30PM via Gradescope Hand-in HANDIN INSTRUCTIONS Download a copy of this PDF file. You have two ways to fill
More informationCSC148 Week 2. Larry Zhang
CSC148 Week 2 Larry Zhang 1 Admin Discussion board is up (link on the course website). 2 Outline for this week Abstract Data Type Stack Queue 3 Abstract Data Type (ADT) 4 What is an abstract data type
More informationConstants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter
Variables, Expressions, and Statements Chapter 2 Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.
More informationSCHEME 7. 1 Introduction. 2 Primitives COMPUTER SCIENCE 61A. October 29, 2015
SCHEME 7 COMPUTER SCIENCE 61A October 29, 2015 1 Introduction In the next part of the course, we will be working with the Scheme programming language. In addition to learning how to write Scheme programs,
More informationSTREAMS AND REVIEW 12
STREAMS AND REVIEW 12 COMPUTER SCIENCE 61A April 23, 2014 1 Streams A stream is our third example of a lazy sequence. A stream is like a lazily evaluated Rlist. In other words, the stream s elements (except
More informationVariable 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 informationCS 320 Midterm Exam Solution
Name: BU ID: CS 320 Midterm Exam Solution Fall 2018 Write here the number of the problem you are skipping: You must complete 4 of the 5 problems on this exam for full credit. Each problem is of equal weight.
More informationAbout Python. Python Duration. Training Objectives. Training Pre - Requisites & Who Should Learn Python
About Python Python course is a great introduction to both fundamental programming concepts and the Python programming language. By the end, you'll be familiar with Python syntax and you'll be able to
More informationRecursive Thinking. Chapter 8: Recursion. Recursive Definitions. Recursion. Java Software Solutions for AP* Computer Science A 2nd Edition
Chapter 8: Recursion Presentation slides for Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem Java Software Solutions for AP* Computer Science
More informationAnd Parallelism. Parallelism in Prolog. OR Parallelism
Parallelism in Prolog And Parallelism One reason that Prolog is of interest to computer scientists is that its search mechanism lends itself to parallel evaluation. In fact, it supports two different kinds
More informationIntroduction to Programming
Introduction to Programming Computers and Programs Python Programming, 1/e 1 The Universal Machine What is a computer program? A detailed, step-by-step set of instructions telling a computer what to do.
More informationData Science Python. Anaconda. Python 3.x. Includes ALL major Python data science packages. Sci-kit learn. Pandas.
Data Science Python Anaconda Python 3.x Includes ALL major Python data science packages Sci-kit learn Pandas PlotPy Jupyter Notebooks www.anaconda.com Python - simple commands Python is an interactive
More informationStructure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1
CS 61A Structure and Interpretation of Computer Programs Spring 2017 Mock Midterm 1 INSTRUCTIONS You have 1 hour to complete the exam. The exam is closed book, closed notes, closed computer, closed calculator,
More informationCS 61B Discussion Quiz 1. Questions
Name: SID: CS 61B Discussion Quiz 1 Write your name and SID above. Detach this page from your discussion handout, and turn it in when your TA instructs you to do so. These quizzes are used as attendance.
More informationVariables, expressions and statements
Variables, expressions and statements 2.1. Values and data types A value is one of the fundamental things like a letter or a number that a program manipulates. The values we have seen so far are 2 (the
More informationmith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut
mith College Computer Science CSC231 Assembly Week #10 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu 2 Videos to Start With https://www.youtube.com/watch?v=fdmzngwchdk https://www.youtube.com/watch?v=k2iz1qsx4cm
More informationLecture 7: Python s Built-in. in Types and Basic Statements
The University of North Carolina at Chapel Hill Spring 2002 Lecture 7: Python s Built-in in Types and Basic Statements Jan 25 1 Built-in in Data Structures: Lists A list is an ordered collection of objects
More informationVisualize 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
More informationroboturtle Documentation
roboturtle Documentation Release 0.1 Nicholas A. Del Grosso November 28, 2016 Contents 1 Micro-Workshop 1: Introduction to Python with Turtle Graphics 3 1.1 Workshop Description..........................................
More informationCompound Data Types 2
Compound Data Types 2 Chapters 10, 11, 12 Prof. Mauro Gaspari: gaspari@cs.unibo.it Objects and Values We know that a and b both refer to a string, but we don t know whether they refer to the same string.
More informationTUPLES 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
More information[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
More informationCSC326 Python Sequences i. CSC326 Python Sequences
i CSC326 Python Sequences ii REVISION HISTORY NUMBER DATE DESCRIPTION NAME 1.0 2011-09 JZ iii Contents 1 Agenda 1 2 while Statement 1 3 Sequence Overview 2 4 String 2 5 Lists 4 6 Dictionary 5 7 Tuples
More informationCMSC 201 Computer Science I for Majors
CMSC 201 Computer Science I for Majors Lecture 02 Intro to Python Syllabus Last Class We Covered Grading scheme Academic Integrity Policy (Collaboration Policy) Getting Help Office hours Programming Mindset
More information