6.189 D ay 6. Name: R eadings. E x er cise 6. 1 { W ar mup: F inding B ugs
|
|
- Diane Gaines
- 5 years ago
- Views:
Transcription
1 6.189 D ay 6 Name: T urn in your written answers to 6.1 and 6.2, stapled to your printed code les, tomorrow at the start of lecture. R eadings How T o T hink L ike A C omputer Scientist, chapter 10. E x er cise 6. 1 { W ar mup: F inding B ugs T he following set of instructions were given to a beginning P ython student, and they produced the code below. F ind at least three bugs and say how to x them. I nstructions: Write a negat e function that takes a number and returns the negation of that number. A lso write a l ar ge numfunction that takes a number, and returns T rue if that number is bigger than 10000, and False otherwise. A dditionally, write some code to test your functions. def negat e( num) : r et ur n - num def l ar ge_num( num) : r es = ( num > 10000) negat e( b) neg_b = num pr i nt ' b: ', b, ' neg_b: ', neg_b bi g = l ar ge_num( b) pr i nt ' b i s bi g: ', bi g B ugs:
2 Exercise 6.2 Warmup: Mystery Program 1 print "Think of a number between 1 and 100, but don t tell me what you choose." 2 min_n = 1 3 max_n = right_answer = False 5 6 while not right_answer: 7 mid_n = (max_n + min_n + 1)/2 8 answer = raw_input( Is it + str(mid_n) +? ) 9 if answer[0] == y : 10 right_answer = True 11 elif answer.startswith( higher ): 12 min_n = mid_n elif answer.startswith( lower ): 14 max_n = mid_n else: 16 print "Sorry, I don t understand your answer." print Woohoo! I got it! 1. The while loop exits when the variable right answer is True. What will cause right answer to be true? 2. How many times will the program print out Woohoo! I got it!? 3. What are we using the variable answer for? 4. The program makes a guess in line 8. What user responses will be understood by the program after it makes its guess? 5. If the program gets the response higher, what does that tell it about its guess? 6. What are the variables min n, max n and mid n used for? This is an example of binary search, a simple but important algorithm in computer science. If you re curious, or confused, read the Wikipedia article on binary search to find out more and get a good explaination of what s going on here. 2
3 E x er cise 6. 3 { A ddit ional L ist P r act ice So far we have been using r aw i nput to get user input. For the remainder of this course we will move away from this function, instead writing functions that take in parameters as opposed to prompting the user for input. So, for this and all following problems, do not use r aw i nput unless ex plicit ly t old t o do so. Write a function l i s t i nt er s ect i on that takes two lists as parameters. Save your work in Day6. py. R eturn a list that gives the intersection of the two lists- ie, a list of elements that are common to both lists. R un the following test cases and make sure your results are the same ( order does not matter): >>> l i s t _i nt er s ect i on( [ 1, 3, 5], [ 5, 3, 1] ) [ 1, 3, 5] >>> l i s t _i nt er s ect i on( [ 1, 3, 6, 9], [ 10, 14, 3, 72, 9] ) [ 3, 9] >>> l i s t _i nt er s ect i on( [ 2, 4, 6], [ 1, 3, 5] ) [ ] E x er cise 6. 4 { A n I nt r oduct ion t o D ict ionar ies Q uick R efer ence D = f g creates an empty dictionary D = f key1: val ue1,... g creates a non-empty dictionary D[ key] returns the value thats mapped to by key. (W hat if there's no such key?) D[ key] = newval ue maps newvalue to key. Overwrites any previous value. del D[ key] deletes the mapping with that key from D. l en( D) returns the number of entries ( mappings) in D. x i n D, x not i n D checks whether the key x is in the dictionary D. Download the code framework called names ages. py from under, Day 6. R ead this le closely, and wherever it says \ Y OU R C ODE HE R E " - well, put your code there! Notice we have de ned two lists at the top of your le: NAMES = [ ' Al i ce', ' Bob', ' Cat hy', ' Dan', ' Ed', ' Fr ank', ' Gar y', ' Hel en', ' I r ene', ' J ack', ' Kel l y', ' Lar r y' ] AGES = [ 20, 21, 18, 18, 19, 20, 20, 19, 19, 19, 22, 19] T hese lists match up, so A lice's age is 20, B ob's age is 21, and so on. Write a function that combines these lists into a dictionary. T hen, write a function that, given an age, returns the names of all the people who are that age. T est your program' s functions by running these lines ( they are commented at the bottom of the code le; uncomment them to use them): pr i nt peopl e( 18) == [ ' Cat hy', ' Dan' ] pr i nt peopl e( 19) == [ ' Ed', ' Hel en', ' I r ene', ' J ack', ' Lar r y' ] pr i nt peopl e( 20) == [ ' Al i ce', ' Fr ank', ' Gar y' ] pr i nt peopl e( 21) == [ ' Bob' ] pr i nt peopl e( 22) == [ ' Kel l y' ] pr i nt peopl e( 23) == [ ] A ll lines should print T rue. I f the last line is giving you an error, look at the name of the error. 3
4 E x er cise 6.5 { M or e on D ict ionar ies Download the file inventory.py, under Day 6. T he le shows eight di erent items, each having a name, a price and a count, like so: HAMMER = ' hammer ' HAMMER_PRI CE = 10 HAMMER_COUNT = 100 We're going to consider that customers generally come in with an idea of how much money they want to spend. So we're going to think of items as either C HE A P (under $20), M ODE R AT E (between $20 and $100) or E X P E NSI V E (over $100). F irst, ll in the variable inventory so that all of the data for the eight items is inside inventory. T hen, implement the function get items that takes a cheapness and returns a list of information about each item that falls under that category, as the function s information says. Important: there should be a loop inside this function. Look at the comments in the code file you download from the webpage; they will help you structure your dictionary in a way that will make this function easier to write. When you re finished, uncomment the test cases and run the program. All of the testing lines should print True. Exercise 6.6 Palindromes (Tricky!) Note: This exercise is tricky! Please ask for help - we really won t think you re stupid for doing so! If you get stuck on it at home, just try your best and get some sleep! It is never good practice to be banging your head against a wall for hours. Visit us at office hours, and turn in whatever progress you can make. Write a function is palindrome which takes a string as parameter, and returns True if the string is a palindrome (meaning it is the same forwards as backwards), and False otherwise. Save your work in Day6.py. Some useful things to remember: Use the function len to find the length of the string. To get just a piece of the string, use the slice operator. For example: string = hello substr = string[1:-1] #sets substr to ell You can decide for yourself whether you want your function to correctly identify palindromes that have spaces (such as able was i ere i saw elba ) It is easiest to do this with a while loop, although there are a few different ways of structuring such a loop. Think about what conditions need to be met for a palindrome to be true, and when you can stop testing for one (hint: the words ana and anna are both palindromes; when do we know to stop checking?) 4
5 Exercise 6.7 Zeller s Algorithm, revisited Optional! If you don t remember what the problem was about, go back and look at problem set 1. Now, create a modular program by breaking the steps of the Zeller s algorithm up into seperate functions. Here is how your program should work (this program will need to use the raw input function): Enter your name: Chuck Norris Enter your date of birth (MMM-DD-YYYY): MAR Chuck Norris, your birthday fell on a Sunday. Hints: 1. Use a dictionary to map between the month and its numerical value. 2. You can use either a list or dictionary to convert the final output of the algorithm to the day of the week. 3. Make sure you handle the following three notes correctly. Note: If the month is January or February, then the preceding year is used for computation. This is because there was a period in history when March 1st, not January 1st, was the beginning of the year. Node: If the computed value of R is a negative number, add 7 to get a nonnegative number between 0 and 6. Note: To convert the string 90 to the number 90, int( 90 ). Save your work in a file zellers redux.py. If you turn it in, we ll take a look at it! 5
6 MIT OpenCourseWare A Gentle Introduction to Programming Using Python January (IAP) 2010 For information about citing these materials or our Terms of Use, visit:
Name & Recitation Section:
Name & Recitation Section: Due Thursday, Jan 13 at 2:10 PM in 34-101. Please print out your code files (homework 3.py, queue.py, and any code you wrote for optional problems), and staple them to the back
More informationTurn in a printout of your code exercises stapled to your answers to the written exercises at 2:10 PM on Thursday, January 13th.
6.189 Homework 3 Readings How To Think Like A Computer Scientist: Monday - chapters 9, 10 (all); Tuesday - Chapters 12, 13, 14 (all). Tuesday s reading will really help you. If you re short on time, skim
More informationRecall that strings and tuples are immutable datatypes, while lists are mutable datatypes. What does this mean?
6.189 Day 4 Readings How To Think Like A Computer Scientist, chapters 7 and 8 6.01 Fall 2009 Course Notes page 27-29 ( Lists and Iterations over lists ; List Comprehensions is optional); sections 3.2-3.4
More informationName & Recitation Section:
Name & Recitation Section: Due Wednesday, Jan 5 at 2:10 PM in 34-101. Please print out your code files (homework 1.py, rps.py, loops.py, and any code you wrote for optional problems), staple them to the
More informationHow To Think Like A Computer Scientist, chapter 3; chapter 6, sections
6.189 Day 3 Today there are no written exercises. Turn in your code tomorrow, stapled together, with your name and the file name in comments at the top as detailed in the Day 1 exercises. Readings How
More information6.189 Project 1. Readings. What to hand in. Project 1: The Game of Hangman. Get caught up on all the readings from this week!
6.189 Project 1 Readings Get caught up on all the readings from this week! What to hand in Print out your hangman code and turn it in Monday, Jaunary 10 at 2:10 PM. Be sure to write your name and section
More informationIntro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming
Intro to Programming Unit 7 Intro to Programming 1 What is Programming? 1. Programming Languages 2. Markup vs. Programming 1. Introduction 2. Print Statement 3. Strings 4. Types and Values 5. Math Externals
More informationIntroduction to Python (All the Basic Stuff)
Introduction to Python (All the Basic Stuff) 1 Learning Objectives Python program development Command line, IDEs, file editing Language fundamentals Types & variables Expressions I/O Control flow Functions
More informationText Input and Conditionals
Text Input and Conditionals Text Input Many programs allow the user to enter information, like a username and password. Python makes taking input from the user seamless with a single line of code: input()
More informationMIT AITI Python Software Development
MIT AITI Python Software Development PYTHON L02: In this lab we practice all that we have learned on variables (lack of types), naming conventions, numeric types and coercion, strings, booleans, operator
More informationGetting Started. Excerpted from Hello World! Computer Programming for Kids and Other Beginners
Getting Started Excerpted from Hello World! Computer Programming for Kids and Other Beginners EARLY ACCESS EDITION Warren D. Sande and Carter Sande MEAP Release: May 2008 Softbound print: November 2008
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 informationControl of Flow. There are several Python expressions that control the flow of a program. All of them make use of Boolean conditional tests.
Control of Flow There are several Python expressions that control the flow of a program. All of them make use of Boolean conditional tests. If Statements While Loops Assert Statements 6 If Statements if
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 informationDecisions, Decisions. Testing, testing C H A P T E R 7
C H A P T E R 7 In the first few chapters, we saw some of the basic building blocks of a program. We can now make a program with input, processing, and output. We can even make our input and output a little
More informationExcerpt from "Art of Problem Solving Volume 1: the Basics" 2014 AoPS Inc.
Chapter 5 Using the Integers In spite of their being a rather restricted class of numbers, the integers have a lot of interesting properties and uses. Math which involves the properties of integers is
More informationIf Statements, For Loops, Functions
Fundamentals of Programming If Statements, For Loops, Functions Table of Contents Hello World Types of Variables Integers and Floats String Boolean Relational Operators Lists Conditionals If and Else Statements
More information6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!
6.S189 Homework 1 http://web.mit.edu/6.189/www/materials.html What to turn in Do the warm-up problems for Days 1 & 2 on the online tutor. Complete the problems below on your computer and get a checkoff
More informationTesting and Debugging
130 Chapter 5 Testing and Debugging You ve written it so it must work, right? By now you know that is not necessarily true. We all make mistakes. To be a successful programmer you need to be able to reliably
More informationMITOCW watch?v=flgjisf3l78
MITOCW watch?v=flgjisf3l78 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To
More informationCMSC 201 Fall 2018 Lab 04 While Loops
CMSC 201 Fall 2018 Lab 04 While Loops Assignment: Lab 04 While Loops Due Date: During discussion, September 24 th through September 27 th Value: 10 points (8 points during lab, 2 points for Pre Lab quiz)
More informationOverview of List Syntax
Lists and Sequences Overview of List Syntax x = [0, 0, 0, 0] Create list of length 4 with all zeroes x 4300112 x.append(2) 3 in x x[2] = 5 x[0] = 4 k = 3 Append 2 to end of list x (now length 5) Evaluates
More informationCMPT 120 Control Structures in Python. Summer 2012 Instructor: Hassan Khosravi
CMPT 120 Control Structures in Python Summer 2012 Instructor: Hassan Khosravi The If statement The most common way to make decisions in Python is by using the if statement. The if statement allows you
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 information1 Getting used to Python
1 Getting used to Python We assume you know how to program in some language, but are new to Python. We'll use Java as an informal running comparative example. Here are what we think are the most important
More informationLecture 10: Boolean Expressions
Lecture 10: Boolean Expressions CS1068+ Introductory Programming in Python Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (12/10/17) Lecture 10: Boolean Expressions
More informationMITOCW watch?v=se4p7ivcune
MITOCW watch?v=se4p7ivcune The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To
More informationPython for Non-programmers
Python for Non-programmers A Gentle Introduction 1 Yann Tambouret Scientific Computing and Visualization Information Services & Technology Boston University 111 Cummington St. yannpaul@bu.edu Winter 2013
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 informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu/program/philippines-summer-2012/ Philippines Summer 2012 Lecture 1 Introduction to Python June 19, 2012 Agenda About the Course What is
More informationPython Programming Challenges
Python Programming Challenges Name Complete the tasks enclosed and complete a self review for each task. Eg: Yes or no errors? Yes syntax errors (write in the error) or No your errors/solve the problem?
More informationCSCE 110: Programming I
CSCE 110: Programming I Sample Questions for Exam #1 February 17, 2013 Below are sample questions to help you prepare for Exam #1. Make sure you can solve all of these problems by hand. For most of the
More informationHello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications
Hello World! Computer Programming for Kids and Other Beginners by Warren Sande and Carter Sande Chapter 1 Copyright 2009 Manning Publications brief contents Preface xiii Acknowledgments xix About this
More information1 Writing recursive functions
1 Writing recursive functions Recall from the previous handout these tips on writing a recursive function: 1) (Doc) Write the docstring first... trust me, it helps! 2) (Base) Figure out the base case:
More informationIntro. 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
More informationTry typing the following in the Python shell and press return after each calculation. Write the answer the program displays next to the sums below.
Name: Date: Instructions: PYTHON - INTRODUCTORY TASKS Open Idle (the program we will be using to write our Python codes). We can use the following code in Python to work out numeracy calculations. Try
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 12 Tuples All materials copyright UMBC and Dr. Katherine Gibson unless otherwise noted Modularity Meaning Benefits Program design Last Class We Covered Top
More informationLOOPS. Repetition using the while statement
1 LOOPS Loops are an extremely useful feature in any programming language. They allow you to direct the computer to execute certain statements more than once. In Python, there are two kinds of loops: while
More informationCS2304: 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
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 08 Lists Constants Last Class We Covered More on while loops Sentinel loops Boolean flags 2 Any Questions from Last Time? 3 Today s Objectives To learn about
More informationPython Evaluation Rules
Python Evaluation Rules UW CSE 160 https://courses.cs.washington.edu/courses/cse160/15sp/ Michael Ernst and Isaac Reynolds mernst@cs.washington.edu April 1, 2015 Contents 1 Introduction 2 1.1 The Structure
More informationECS 10 Concepts of Computation Example Final Problems
ECS 10 Concepts of Computation Example Final Problems 1. Here is a little program, not necessarily correct. ages= {} ages["cat"]=4 if 4 in ages: print ages[4] This program will... a) print cat b) print
More informationProgram Planning, Data Comparisons, Strings
Program Planning, Data Comparisons, Strings Program Planning Data Comparisons Strings Reading for this class: Dawson, Chapter 3 (p. 80 to end) and 4 Program Planning When you write your first programs,
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification
More informationPython: common syntax
Lab 09 Python! Python Intro Main Differences from C++: True and False are capitals Python floors (always down) with int division (matters with negatives): -3 / 2 = -2 No variable data types or variable
More informationFractions and their Equivalent Forms
Fractions Fractions and their Equivalent Forms Little kids use the concept of a fraction long before we ever formalize their knowledge in school. Watching little kids share a candy bar or a bottle of soda
More information6.096 Introduction to C++
MIT OpenCourseWare http://ocw.mit.edu 6.096 Introduction to C++ January (IAP) 2009 For information about citing these materials or our Terms of Use, visit: http://ocw.mit.edu/terms. Massachusetts Institute
More informationDiscussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:
Discussion 1H Notes (Week 3, April 14) TA: Brian Choi (schoi@cs.ucla.edu) Section Webpage: http://www.cs.ucla.edu/~schoi/cs31 More on Arithmetic Expressions The following two are equivalent:! x = x + 5;
More informationProgramming Fundamentals and Python
Chapter 2 Programming Fundamentals and Python This chapter provides a non-technical overview of Python and will cover the basic programming knowledge needed for the rest of the chapters in Part 1. It contains
More informationDECOMPOSITION, ABSTRACTION, FUNCTIONS
DECOMPOSITION, ABSTRACTION, FUNCTIONS (download slides and.py files follow along!) 6.0001 LECTURE 4 6.0001 LECTURE 4 1 LAST TIME while loops vs for loops should know how to write both kinds should know
More informationHacettepe University Computer Engineering Department. Programming in. BBM103 Introduction to Programming Lab 1 Week 4. Fall 2018
Hacettepe University Computer Engineering Department Programming in BBM103 Introduction to Programming Lab 1 Week 4 Fall 2018 Install PyCharm Download Link : https://www.jetbrains.com/pycharm-edu/download/#section=windows
More informationFlow Control. So Far: Writing simple statements that get executed one after another.
Flow Control So Far: Writing simple statements that get executed one after another. Flow Control So Far: Writing simple statements that get executed one after another. Flow control allows the programmer
More informationAbstract Data Types. CS 234, Fall Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples
Abstract Data Types CS 234, Fall 2017 Types, Data Types Abstraction Abstract Data Types Preconditions, Postconditions ADT Examples Data Types Data is stored in a computer as a sequence of binary digits:
More informationFunctions and Decomposition
Unit 4 Functions and Decomposition Learning Outcomes Design and implement functions to carry out a particular task. Begin to evaluate when it is necessary to split some work into functions. Locate the
More informationn! = 1 * 2 * 3 * 4 * * (n-1) * n
The Beauty and Joy of Computing 1 Lab Exercise 9: Problem self-similarity and recursion Objectives By completing this lab exercise, you should learn to Recognize simple self-similar problems which are
More informationCMSC201 Computer Science I for Majors
CMSC201 Computer Science I for Majors Lecture 08 Lists Constants Last Class We Covered More on while loops Sentinel loops Priming Reads Boolean flags 2 Any Questions from Last Time? 3 Today s Objectives
More informationCME 193: Introduction to Scientific Python Lecture 1: Introduction
CME 193: Introduction to Scientific Python Lecture 1: Introduction Nolan Skochdopole stanford.edu/class/cme193 1: Introduction 1-1 Contents Administration Introduction Basics Variables Control statements
More informationAccelerating Information Technology Innovation
Accelerating Information Technology Innovation http://aiti.mit.edu Cali, Colombia Summer 2012 Lesson 1 Introduction to Python Agenda What is Python? and Why Python? Basic Syntax Strings User Input Useful
More informationTypes, 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 "+
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 informationMunster Programming Training - Cycle 2
Munster Programming Training - Cycle 2 Lecture 3 - Binary Search & Queues & Stacks Bastien Pietropaoli bastien.pietropaoli@insight-centre.org Time complexity Previously On MPT Cycle 2 Recursions Exercise
More informationIntro. Speed V Growth
Intro Good code is two things. It's elegant, and it's fast. In other words, we got a need for speed. We want to find out what's fast, what's slow, and what we can optimize. First, we'll take a tour of
More information(Refer Slide Time: 01.26)
Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture # 22 Why Sorting? Today we are going to be looking at sorting.
More informationLoop structures and booleans
Loop structures and booleans Michael Mandel Lecture 7 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture07final.ipynb
More informationCSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch
CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch Purpose: We will take a look at programming this week using a language called Scratch. Scratch is a programming language that was developed
More informationControl Structure: Selection
Control Structure: Selection Knowledge: Understand various concepts of selection control structure Skill: Be able to develop a program containing selection control structure Selection Structure Single
More informationLecture. Loops && Booleans. Richard E Sarkis CSC 161: The Art of Programming
Lecture Loops && Booleans Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda (In-)definite loops (for/while) Patterns: interactive loop and sentinel loop Solve problems using (possibly
More informationIntroduction to Bioinformatics
Introduction to Bioinformatics Variables, Data Types, Data Structures, Control Structures Janyl Jumadinova February 3, 2016 Data Type Data types are the basic unit of information storage. Instances of
More informationOutline: Search and Recursion (Ch13)
Search and Recursion Michael Mandel Lecture 12 Methods in Computational Linguistics I The City University of New York, Graduate Center https://github.com/ling78100/lectureexamples/blob/master/lecture12final.ipynb
More information3. Conditional Execution
3. Conditional Execution Topics: Boolean values Relational operators if statements The Boolean type Motivation Problem: Assign positive float values to variables a and b and print the values a**b and b**a.
More informationFractions and their Equivalent Forms
Fractions Fractions and their Equivalent Forms Little kids use the concept of a fraction long before we ever formalize their knowledge in school. Watching little kids share a candy bar or a bottle of soda
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 information1. What is the difference between a local variable and an object s attribute?
6.189 Day 7 Name: Readings How To Think Like A Computer Scientist, chapters 12, 13 and 14. Exercise 7.1 Short Answers 1. What is the difference between a local variable and an object s attribute? 2. What
More informationDCS/100: Procedural Programming
DCS/100: wk 3 p.1/50 DCS/100: Procedural Programming Week 3: Making Decisions Queen Mary, University of London DCS/100: wk 3 p.2/50 Last Week From last week you should be able to explain and write programs
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 informationFlow Control: Branches and loops
Flow Control: Branches and loops In this context flow control refers to controlling the flow of the execution of your program that is, which instructions will get carried out and in what order. In the
More informationCOMP 4/6262: Programming UNIX
COMP 4/6262: Programming UNIX Lecture 12 shells, shell programming: passing arguments, if, debug March 13, 2006 Outline shells shell programming passing arguments (KW Ch.7) exit status if (KW Ch.8) test
More informationCSC148, Lab #4. General rules. Overview. Tracing recursion. Greatest Common Denominator GCD
CSC148, Lab #4 This document contains the instructions for lab number 4 in CSC148H. To earn your lab mark, you must actively participate in the lab. We mark you in order to ensure a serious attempt at
More information7. Tile That Courtyard, Please
7. Tile That Courtyard, Please We shape our buildings; thereafter they shape us. Winston Churchill. Programming constructs and algorithmic paradigms covered in this puzzle: List comprehension basics. Recursive
More informationFractions and their Equivalent Forms
Fractions Fractions and their Equivalent Forms Little kids use the concept of a fraction long before we ever formalize their knowledge in school. Watching little kids share a candy bar or a bottle of soda
More informationLecture 5 8/24/18. Writing larger programs. Comments. What are we going to cover today? Using Comments. Comments in Python. Writing larger programs
What are we going to cover today? Lecture 5 Writing and Testing Programs Writing larger programs Commenting Design Testing Writing larger programs As programs become larger and more complex, it becomes
More informationCoding Workshop. Learning to Program with an Arduino. Lecture Notes. Programming Introduction Values Assignment Arithmetic.
Coding Workshop Learning to Program with an Arduino Lecture Notes Table of Contents Programming ntroduction Values Assignment Arithmetic Control Tests f Blocks For Blocks Functions Arduino Main Functions
More informationBuilt-in functions. You ve used several functions already. >>> len("atggtca") 7 >>> abs(-6) 6 >>> float("3.1415") >>>
Functions Built-in functions You ve used several functions already len("atggtca") 7 abs(-6) 6 float("3.1415") 3.1415000000000002 What are functions? A function is a code block with a name def hello():
More informationThe following content is provided under a Creative Commons license. Your support
MITOCW Recitation 1 The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high-quality educational resources for free. To make
More informationCSC148H Week 3. Sadia Sharmin. May 24, /20
CSC148H Week 3 Sadia Sharmin May 24, 2017 1/20 Client vs. Developer I For the first couple of weeks, we have played the role of class designer I However, you are also often in the opposite role: when a
More informationCSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions. User Defined Functions
CSci 1113, Fall 2015 Lab Exercise 4 (Week 5): Write Your Own Functions User Defined Functions In previous labs, you've encountered useful functions, such as sqrt() and pow(), that were created by other
More informationPython Class-Lesson1 Instructor: Yao
Python Class-Lesson1 Instructor: Yao What is Python? Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Its high-level built in data structures, combined
More informationWorking with Z3 (10 points)
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.820 Foundations of Program Analysis Problem Set 4 Out: October 22, 2015 Due: Nov 6, 2015 at 5:00 PM In
More informationLecture Transcript While and Do While Statements in C++
Lecture Transcript While and Do While Statements in C++ Hello and welcome back. In this lecture we are going to look at the while and do...while iteration statements in C++. Here is a quick recap of some
More informationWELCOME! (download slides and.py files and follow along!) LECTURE 1
WELCOME! (download slides and.py files and follow along!) 6.0001 LECTURE 1 6.0001 LECTURE 1 1 TODAY course info what is computation python basics mathematical operations python variables and types NOTE:
More informationMITOCW watch?v=0jljzrnhwoi
MITOCW watch?v=0jljzrnhwoi The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To
More informationthe rules The Goal Get all three of your monkeys around the board and into the Banana Grove before anyone else can!
the rules Equipment Code Monkey Island Gameboard, 12 monkey figurines (three of each color), 54 Guide cards, 16 Fruit cards, 10 Boost in a Bottle cards. The Goal Get all three of your monkeys around the
More informationMITOCW watch?v=rvrkt-jxvko
MITOCW watch?v=rvrkt-jxvko The following content is provided under a Creative Commons license. Your support will help MIT OpenCourseWare continue to offer high quality educational resources for free. To
More informationAt full speed with Python
At full speed with Python João Ventura v0.1 Contents 1 Introduction 2 2 Installation 3 2.1 Installing on Windows............................ 3 2.2 Installing on macos............................. 5 2.3
More informationHash Tables COS 217 1
Hash Tables COS 217 1 Goals of Today s Lecture Motivation for hash tables o Examples of (key, value) pairs o Limitations of using arrays o Example using a linked list o Inefficiency of using a linked list
More informationPart 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.
More informationPhysics 1230: Light and Color. Projects
Physics 1230: Light and Color Chuck Rogers, Charles.Rogers@colorado.edu Matt Heinemann, Matthew.Heinemann@colorado.edu www.colorado.edu/physics/phys1230 Exam 2 tomorrow, here. HWK 6 is due at 5PM Thursday.
More informationWatch the video below to learn more about number formats in Excel. *Video removed from printing pages. Why use number formats?
Excel 2016 Understanding Number Formats What are number formats? Whenever you're working with a spreadsheet, it's a good idea to use appropriate number formats for your data. Number formats tell your spreadsheet
More informationRoc Model and Density Dependence, Part 1
POPULATION MODELS Roc Model and Density Dependence, Part 1 Terri Donovan recorded: February, 2012 You ve now completed several modeling exercises dealing with the Roc population. So far, the caliph of
More informationTo become familiar with array manipulation, searching, and sorting.
ELECTRICAL AND COMPUTER ENGINEERING 06-88-211: COMPUTER AIDED ANALYSIS LABORATORY EXPERIMENT #2: INTRODUCTION TO ARRAYS SID: OBJECTIVE: SECTIONS: Total Mark (out of 20): To become familiar with array manipulation,
More information