Compsci 101.2, Fall 2015 9.1 PFTheWeek 9/21-9/25 l Potpourri, Hodgepodge of Review Concepts  File reading and writing  Boolean expressions  Arithmetic.

Slides:



Advertisements
Similar presentations
CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
Advertisements

CompSci 101 Introduction to Computer Science February 3, 2015 Prof. Rodger Lecture given by Elizabeth Dowd.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Mathematical. Approach  Many of these problems read as brain teasers at first, but can be worked through in a logical way.  Just remember to rely on.
I210 review Fall 2011, IUB. Python is High-level programming –High-level versus machine language Interpreted Language –Interpreted versus compiled 2.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Professor Jennifer Rexford COS 217
Compsci 101.2, Fall PFTT (plan for this Thursday) l What is a Python program?  In the context of what we do in Compsci 101  In a neuroscience.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
Lecture 06 – Reading and Writing Text Files.  At the end of this lecture, students should be able to:  Read text files  Write text files  Example.
CIT 590 Intro to Programming Lecture 4. Agenda Doubts from HW1 and HW2 Main function Break, quit, exit Function argument names, scope What is modularity!
 Expression Tree and Objects 1. Elements of Python  Literals, Strings, Tuples, Lists, …  The order of file reading  The order of execution 2.
Compsci 101.2, Fall PFThursday l Review Organization and Problem-Solving  Defining functions, calling functions  Return types, print, None l.
Compsci 06/101, Fall What will you do in Compsci 6 Today? l Learn about selection and if/else statements  In context of solving problems  Understanding.
Session Three Review & Conditional Control Flow. Java File Hierarchy Projects Packages Classes Methods.
CompSci Arrays  Aggregate data type  Deal with items of same type  Lists of words  Numbers  Analogies  Mailboxes in post office  CD racks.
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
Compsci 101.2, Fall PFTWeek l Introduce new Python concepts  Control: if, elif, else, for  Data: Strings, Lists Operators on data: slicing,
Compsci 101.2, Fall #TBT l Finish some Python concepts and questions from earlier  Review for midterm exam l Strategies for success in 101 assignments.
Compsci 101.2, Fall Plan for FFWOO l Programming in the small and in the large  Making one function work correctly, especially in the context.
ENCRYPTION TAKE 2: PRACTICAL DETAILS David Kauchak CS52 – Spring 2015.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Programming Perl in UNIX Course Number : CIT 370 Week 3 Prof. Daniel Chen.
Xiaojuan Cai Computational Thinking 1 Lecture 8 Loop Structure Xiaojuan Cai (蔡小娟) Fall, 2015.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 11 Using strings and sequences 5/02/09 Python Mini-Course: Day 3 – Lesson.
Compsci 101.2, Fall Plan for 11/9 and 11/11 l Reviewing Concepts for test  Loops: index and by element  Strings, Lists, Sets, Dictionaries.
Midterm Review Important control structures Functions Loops Conditionals Important things to review Binary Boolean operators (and, or, not) Libraries (import.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
Language Find the latest version of this document at
Compsci 101.2, Fall Plan for WEFWOO l Review for exam, studying and practicing for exams and APTs in Compsci 101  Why memorization doesn't help.
Expressions Methods if else Statements Loops Potpourri.
Compsci 82, Fall Peer to Peer l What is peer to peer?  Useful? Disruptive?  Manageable, governable?  Architecture l Napster, Gnutella, Limeware,
Compsci 06/101, Spring Compsci 6: PFTW l Problem solving and (Python) programming  What are the steps in solving an APT?  How do you get better.
CompSci 101 Introduction to Computer Science February 4, 2016 Prof. Rodger compsci101 spring161.
5.02B Decision Making Structure (part 2). Compound Boolean Expressions.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
CompSci 101 Introduction to Computer Science February 11, 2016 Prof. Rodger.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Lecture 14 – lists, for in loops to iterate through the elements of a list COMPSCI 1 1 Principles of Programming.
CompSci 101 Introduction to Computer Science February 16, 2016 Prof. Rodger “All your troubles are due to those ‘ifs’,” declared the Wizard. If you were.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
Random Functions Selection Structure Comparison Operators Logical Operator
11 March 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Q and A for Section 4.4 CS 106, Fall If statement syntax Q: The syntax for an if statement (or conditional statement) is: if _______________ : _____________.
 Type Called bool  Bool has only two possible values: True and False.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Introduction to Python
CompSci 101 Introduction to Computer Science
Python: Control Structures
CSc 110, Spring 2017 Lecture 14: Boolean Logic and Midterm Review
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
CSc 110, Autumn 2016 Lecture 14: Boolean Logic
.Net Programming with C#
More about Numerical Computation
Georgia Institute of Technology
Adapted from slides by Marty Stepp and Stuart Reges
Introduction to Programming Using Python PART 2
CSc 110, Spring 2018 Lecture 13: Cumulative Sum and Boolean Logic
Compsci 6/101: PFTW Review how APTs and Python work, run
Python Basics with Jupyter Notebook
COMPUTING.
CompSci 101 Introduction to Computer Science
Presentation transcript:

Compsci 101.2, Fall PFTheWeek 9/21-9/25 l Potpourri, Hodgepodge of Review Concepts  File reading and writing  Boolean expressions  Arithmetic operators  Helpful methods and functions l Lab, Midterm, Assignment, APT Quiz  Review concepts for lab, lab helps with midterm  How do you tackle an assignment that has so many parts?

Compsci 101.2, Fall Software in the News If car.isDriving() or car.onRoad(): gofaster() emit_more() get_performance() elif car.connectedToMonitor(): beclean() register_as_wonderful() else: act_randomly() engine_light_on()

Compsci 101.2, Fall Reading from Files, Writing to Files l Programs generate data, store for access  Notes we take, notebooks we keep  Files we make our programs create and add to l File concepts for reading and writing  Call open with a path to file, how to open?  Choice of reading, writing, appending  Read or Write (depending on "r", "a", "w")  Close the file when done

Compsci 101.2, Fall Reading from files: see Pigify.py l Open file for reading  Read lines: for line in f:  Read file: f.read()  Both get strings, convert as needed l If fname not found? l Type of f? l Type of st? def readFile(fname): f = open(fname) st = f.read() f.close() return st.split()

Compsci 101.2, Fall Code in Pigify.py def writeFile(words, fname): LINE_SIZE = 80 f = open(fname,"w") wcount = 0 for word in words: f.write(word) wcount += len(word) if wcount + 1 > LINE_SIZE: f.write('\n') wcount = 0 else: f.write(' ') f.close()

Compsci 101.2, Fall Questions: File writing and Transform

Compsci 101.2, Fall Compound Boolean Expressions l Is the second character a vowel? if is_vowel(s[1]): l What if word has only one character? if len(s) > 1 and is_vowel(s[1]): if is_vowel(s[1]) and len(s) > 1: l Short-circuit evaluation: A false/true if A and B: if A or B:

Compsci 101.2, Fall Boolean expression review l How do we figure out what this means?  DeMorgan's Laws help  NOT(A and B) === NOT(A) or NOT(B)  NOT(A or B) === NOT(A) and NOT(B) if not(len(s) < 5 or is_vowel(s[1])): if not len(s) < 5 and not is_vowel(s[1])): if len(s) >= 5 and not is_vowel(s[1])):

Compsci 101.2, Fall Brian Fox l GNU Bash Shell (developer) l Buddycast (co-developer) “each person has a sweet spot — a place where they are incredibly productive and at their happiest while doing so — okorians spend their lives living there — the okori sweet spot is the realization of the concept, the delivery of the impossible, from the germ of the idea to the instantiation of it”

Compsci 101.2, Fall YALALA l Yet Another Look At Loop and Accumulate  Initialize before loop: list, int, string  Accumulate in loop:.append, +=, +=  Return value after the loop: change as needed l What can we loop over?  List: get elements one at a time  Strings: get characters one at a time  Range: get numbers one at a time Use range elements to index lists or strings

Compsci 101.2, Fall APT and Transform Review def pigall(st): all = [] for word in st.split(): all.append(pigword(word)) return ' '.join(all) def encrypt(str, shift): all = [] for word in str.split(): all.append(shiftword(word,shift)) return ' '.join(all)

Compsci 101.2, Fall APT and Transform Review def lovely(ingre,inedible): c = 0 for xx in yy: if not x-expression: c = c + 1 return c def getMessage(original): trans = [] for word in original.split(): trans.append(transform(word)) return ' '.join(trans)

Compsci 101.2, Fall From Loops to Turtles to Numbers l Computers are used for simulations  Weather forecasting We have models that work sometimes, use them Test our simulations against past data  Stock-market High Frequency Trading How do you know your new algorithm works? Test it with small $$, Test against history, … l Sometimes visualizing helps  Code visualization  Simulation visualization in lab this week Run Walker.py, look at visualization to check

Compsci 101.2, Fall What is the S in HTTPS? l How do we make secure transactions?  Encrypt so that decryption "impossible"  What does impossible mean? l Depends on deep results from math, we can appreciate these at a high (shallow) level  Multiply two prime numbers: 53 x 47 = 2491  Can we factor 2491 into two primes?  Primality is "easy", Factoring is "hard"

Compsci 101.2, Fall isPrime the easy way, takes "forever" l Divisors of 28 are: 2, 4, 7, 14 l Divisors of 289 are: 17 l Divisors of N come in pairs, X and N/X  Use actual numbers for N and X: 64 and 16, … l If there's a factor …  There's one less than or equal to √N l Plan for testing divisors  Keep trying, if we find one … otherwise …

Compsci 101.2, Fall Writing and Testing code l Conceptually: when can we return True?  When can we return False --- not prime l What are special cases? def isprime(num): limit = int(math.sqrt(num)) + 1 # not showing special cases for div in range(3,limit,2): if num % div == 0: return False return True

Compsci 101.2, Fall Counting Questions