Introduction to: Computers & Programming: Review prior to 1 st Midterm

Similar documents
Introduction to: Computers & Programming: Review prior to 2 nd Midterm

Lecture 3. Input, Output and Data Types

Part III Appendices 165

age = 23 age = age + 1 data types Integers Floating-point numbers Strings Booleans loosely typed age = In my 20s

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

CS1 Lecture 3 Jan. 22, 2018

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

COMP1730/COMP6730 Programming for Scientists. Data: Values, types and expressions.

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS1 Lecture 3 Jan. 18, 2019

ENGR 102 Engineering Lab I - Computation

Python: common syntax

Python Unit

CPS122 Lecture: From Python to Java last revised January 4, Objectives:

Full file at

ENGR 101 Engineering Design Workshop

Professor: Sana Odeh Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators

Python for Non-programmers

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

cs1114 REVIEW of details test closed laptop period

PRG PROGRAMMING ESSENTIALS. Lecture 2 Program flow, Conditionals, Loops

Key Differences Between Python and Java

Introduction to Python Programming

Variables, Constants, and Data Types

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

KOMAR UNIVERSITY OF SCIENCE AND TECHNOLOGY (KUST)

Introduction to Computer Programming CSCI-UA 2. Review Midterm Exam 1

Full file at

Python for C programmers

Fundamentals of Programming (Python) Getting Started with Programming

Java Bytecode (binary file)

ENGR 102 Engineering Lab I - Computation

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

Programming for Engineers in Python. Autumn

Introduction to: Computers & Programming: Strings and Other Sequences

CPS122 Lecture: From Python to Java

Introduction to Python and programming. Ruth Anderson UW CSE 160 Winter 2017

Computer and Programming: Lab 1

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Programming with Python

Lecture 1. Course Overview, Python Basics

Chapter 2 Working with Data Types and Operators

CS 115 Lecture 4. More Python; testing software. Neil Moore

Built-in Types of Data

Accelerating Information Technology Innovation

Introduction to Scientific Python, CME 193 Jan. 9, web.stanford.edu/~ermartin/teaching/cme193-winter15

CS1110 Lab 1 (Jan 27-28, 2015)

Reviewing all Topics this term

Scripting Languages. Python basics

C: How to Program. Week /Mar/05

Lecture 1. Course Overview, Python Basics

Python 1: Intro! Max Dougherty Andrew Schmitt

Discussion 1H Notes (Week 3, April 14) TA: Brian Choi Section Webpage:

Chapter 2 Getting Started with Python

CS 106 Introduction to Computer Science I

Getting Started with Python

Algorithms and Programming I. Lecture#12 Spring 2015

CSE 115. Introduction to Computer Science I

Python Programming Exercises 1

CS 115 Data Types and Arithmetic; Testing. Taken from notes by Dr. Neil Moore

Introduction to: Computers & Programming Defining Identifiers: Objects with Names

Python Input, output and variables

06/11/2014. Subjects. CS Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / ) Beginning with Python

Programming for Engineers in Python. Recitation 1

Accelerating Information Technology Innovation

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016

CSI33 Data Structures

Decisions, Decisions. Testing, testing C H A P T E R 7

CS 1110, LAB 1: PYTHON EXPRESSIONS.

FRAC: Language Reference Manual

GridLang: Grid Based Game Development Language Language Reference Manual. Programming Language and Translators - Spring 2017 Prof.

Objectives. In this chapter, you will:

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

MODULE 02: BASIC COMPUTATION IN JAVA

Course Outline. Introduction to java

CS1114 Spring 2015 Test ONE ANSWER KEY. page 1 of 8 pages (counting the cover sheet)

Computers Programming Course 6. Iulian Năstac

Lab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han

Getting Started. Office Hours. CSE 231, Rich Enbody. After class By appointment send an . Michigan State University CSE 231, Fall 2013

MICROPROCESSOR SYSTEMS INTRODUCTION TO PYTHON

Teaching London Computing

STATS 507 Data Analysis in Python. Lecture 2: Functions, Conditionals, Recursion and Iteration

The current topic: Python. Announcements. Python. Python

CSCE 110 Programming I Basics of Python: Variables, Expressions, Input/Output

Computer Science is...

Python as a First Programming Language Justin Stevens Giselle Serate Davidson Academy of Nevada. March 6th, 2016

VENTURE. Section 1. Lexical Elements. 1.1 Identifiers. 1.2 Keywords. 1.3 Literals

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Getting started with Java

Chapter 2 Input, Processing and Output. Hong Sun COSC 1436 Spring 2017 Jan 30, 2017

Python I. Some material adapted from Upenn cmpe391 slides and other sources

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

More Data Types. The Char Data Type. Variable Declaration. CS200: Computer Science I. Module 14 More Data Types

At full speed with Python

Module 01: Introduction to Programming in Python

Getting Started Values, Expressions, and Statements CS GMU

VARIABLES. Aim Understanding how computer programs store values, and how they are accessed and used in computer programs.

Variable and Data Type I

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Transcription:

Introduction to: Computers & Programming: Review prior to 1 st Midterm Adam Meyers New York University

Summary Some Procedural Matters Summary of what you need to Know For the Test and To Go Further in the Class One Practice in-class writing of program I will give everyone 15 minutes to write the same basic program independentally

Procedural Matters Regarding the Midterm The class will be proctored by 1 or 2 people (depending on class size). If possible, there will be at least one empty seat between students I will take attendance please bring your School ID The test will be graded on a curve Each midterm counts for 20% of the final grade If you are auditing and want to take the midterm, please let me know in advance and I will try to figure something out.

Type of Questions that Could Be on the Test Section I: Answer questions about Code What is printed out? What is the value of a variable after code executes? Section II: Find and correct errors in code Identify errors State how to correct the errors Section III: Write functions that solve simple problems involving: user input, printing, calculating values, etc.

What you should know Topics: algorithm, program, programming language, function, operator, input, output, side effect, variable, scope, data types, simple for loops, etc. Know how to: Define functions Assign values to variables Return values from functions Use print statements, input statements, operators Import modules Use data types and coerce one data type to another Write a simple function that works and is easy to understand, due to comments and variable/function names

Algorithms and Programs An Algorithm step by step plan for solving a problem Program Executable implementation of algorithm, written in a computer language Programming Language Formal language for writing computer programs Python High level computer language Popular for teaching and for writing not-too-large programs

More on Algorithms Pseudo Code: a series of ordered statements Structured using line numbers, indents, bullets, etc. Connected by logical and temporal connectors if, else, unless, not, until, when Flow Chart: Connected Series of Boxes circles/ovals = start/end Rectangles = steps in processing Diamonds = Decisions Arrows = Sequence of Steps

Functions Programming language Functions have 3 optional features: Input Output Side effects print versus return print is significant for its side effect printing to the computer screen return Exits block (function) Provides a value to a function (maps to the domain)

Data Types Floats and Integers Strings Boolean (True or False) Nonetype (Output of void functions, like print)

String Components Two identical delimiters:, ', ''' The Characters between delimiters including: digits (0-9) letters(a,b,c,..z,a,b,c,...,z, space) escape characters: \n, \t, \' Sample Strings: '!@##$^&*())' This is an apostrophe: ' 'This is a double quote: ' '''Triple quotes can include ' or or between them'''

More on Strings When working with strings they are represented so it is easy to see all their components: 'The quote \' and the newline \n are useful' When printed, a string will be displayed in a way that interprets these components. The quote ' and the newline are useful The delimiters are eliminated and escape characters are interpreted.

Numbers Integers: No Decimal Place Float Limited in Length Used for numbers with decimals Approximations using Scientific Notation Normal Division with Integer Input Output is a float Integer Division (//) Input/Output are integers (output is floor of answer) Import Math library for many special functions/variables

Type Conversion Functions (Numbers) Float Converts Integers and compatible strings to floats Int Converts floats (by truncation) to integer Converts compatible string to integer Converted Strings can participate in math operations 5 * int('5') 20 / float('5.5')

Converting Non-Strings to Strings str(5.55) '5.55' Makes a string out of any type of object (using definition of that object) Once converted, non-strings can be combined with strings through concatenation 'The number is '+str(5) output = 5+100 'The sum of 5 and 100 is '+ output

Operators Know all the mathematical operators and what they do: +, -, *, **, /, //, % Be familiar with the two equal signs The assignment operator = The test for equality operator == Understand how most of the operators can be restated as functions Note that the assignment operator = cannot be simulated as a function

Making Code Readable Comments ## Know How to use comments ## Know Why to use comments Naming Variables and Functions Choosing names that are self explanatory

Identifiers Functions How to define functions Legal names for functions Using colon, parentheses and indents Variables Legal names of variables Scope global versus local Python defaults regarding 2 variables with the same name, but different scope properties When a variable is passed as an argument of a function, does the function use the actual variable or its value?

for Loops The first line of a for loop: Is of the form for VARIABLE in SEQUENCE: VARIABLE refers to some variable name (item, character, number, etc.) SEQUENCE refers to a sequence (range(5), 'hello', etc.) The body of the loop is indented directly beneath the first line The body repeats one time for each element in the sequence On each iteration, VARIABLE is set to the next item in the sequence.

Sample for loop def diagonal_print(word): number = 0 for letter in word: print(number*' ',letter,sep='') number=number+1 Try it in IDLE

Practice: In-class Exercise Everybody implement the following function independently. You are writing a function for use with a pair of binoculars with a zoom lens. The Lens allows for magnification from 10 times to 100 times. The user enters the magnification M to be used To multiply the apparent width and height of any object in view by a factor of M The user enters the current relative size of the object on a scale from 1 to 10000 1 is 1/10000 th of the area of view and 10000 is the entire field of vision. The object can be larger than the field of vision. The program outputs the new relative size.

Reminder: A Test is a Game Unfortunately, tests are imperfect because some people know how to play better than others. How to win the test game Study sample test instructions Time is a crucial factor (you have just over 1 hour) Do easy problems before hard ones Do not spend a lot of time on a low-point problem Do not get stuck on details that you don't need Example: On practice test, it is not always necessary to understand the program to locate bugs. It takes less time Go for partial credit on program questions (most points) If you cannot program some detail write pseudo code Basic solution strategy is more important than perfect syntax

The Midterm is in 2 (or more) Classes That means that you have a whole week To prepare as you see fit To ask questions to lab tutors, the email tutor and myself Next Class You will have opportunities to discuss problems You have a few days to figure out what those problems are Good luck!