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

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

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

HUDSONVILLE HIGH SCHOOL COURSE FRAMEWORK

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

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

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

L-System Fractal Generator: Language Reference Manual

Built-in Types of Data

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

1/11/2010 Topic 2: Introduction to Programming 1 1

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

PYTHON- AN INNOVATION

Topic 2: Introduction to Programming

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

Fundamentals: Expressions and Assignment

Lecture 2 Tao Wang 1

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

Programming. We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems.

ENGR 101 Engineering Design Workshop

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

egrapher Language Reference Manual

Chapter 4: Basic C Operators

XQ: An XML Query Language Language Reference Manual

Typescript on LLVM Language Reference Manual

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

Full file at

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

CSI Lab 02. Tuesday, January 21st

ENGG1811 Computing for Engineers Week 1 Introduction to Programming and Python

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

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

Basic types and definitions. Chapter 3 of Thompson

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

Chapter 17. Fundamental Concepts Expressed in JavaScript

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

Learning the Language - V

Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Python Intro GIS Week 1. Jake K. Carr

Introduction to Python, Cplex and Gurobi

COMP519 Web Programming Lecture 11: JavaScript (Part 2) Handouts

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018

Variables, expressions and statements

Expr Language Reference

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

PYTHON. Values and Variables

Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Algorithms and Programming I. Lecture#12 Spring 2015

Fundamental of Programming (C)

4. Inputting data or messages to a function is called passing data to the function.

GIS 4653/5653: Spatial Programming and GIS. More Python: Statements, Types, Functions, Modules, Classes

COMP519 Web Programming Lecture 17: Python (Part 1) Handouts

Chapter 2. C++ Basics. Copyright 2014 Pearson Addison-Wesley. All rights reserved.

Chapter 2. Lexical Elements & Operators

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Basic data types. Building blocks of computation

VLC : Language Reference Manual

Visual C# Instructor s Manual Table of Contents

Fundamentals of Programming

Full file at

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

ARG! Language Reference Manual

Expressions and Variables

Chapter 2 Getting Started with Python

Angela Z: A Language that facilitate the Matrix wise operations Language Reference Manual

Level 3 Computing Year 2 Lecturer: Phil Smith

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

Selection statements. CSE 1310 Introduction to Computers and Programming Alexandra Stefan University of Texas at Arlington

Chapter 2: Using Data

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

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

Creating a C++ Program

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Python The way of a program. Srinidhi H Asst Professor Dept of CSE, MSRIT

Computer Components. Software{ User Programs. Operating System. Hardware

BASIC ELEMENTS OF A COMPUTER PROGRAM

Chapter 2. C++ Basics

Java Bytecode (binary file)

Expressions. Eric Roberts Handout #3 CSCI 121 January 30, 2019 Expressions. Grace Murray Hopper. Arithmetic Expressions.

ANSI C Programming Simple Programs

Variables and Values

CS 141, Lecture 3. Please login to the Math/Programming profile, and look for IDLE (3.4 or the unnumbered. <-- fine <-- fine <-- broken

Data Types and Variables in C language

CSI33 Data Structures

Fundamental Data Types. CSE 130: Introduction to Programming in C Stony Brook University

Sketchpad Graphics Language Reference Manual. Zhongyu Wang, zw2259 Yichen Liu, yl2904 Yan Peng, yp2321

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

COMP Primitive and Class Types. Yi Hong May 14, 2015

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

Lexical Considerations

Lecture 3. Input, Output and Data Types

Introduction to Python Programming

1 Lexical Considerations

Programming in Python 3

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

The Warhol Language Reference Manual

DaMPL. Language Reference Manual. Henrique Grando

Introduction to TURING

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Programming for Engineers Introduction to C

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

Transcription:

Review Midterm Exam 1

Review Midterm Exam 1 Exam on Monday, October 7

Data Types and Variables =

Data Types and Variables Basic Data Types Integers Floating Point Numbers Strings

Data Types and Variables Integer int A whole number Can be of unlimited size Be careful not to use commas in your numbers, for example: 1,000

Data Types and Variables Floating point number float A number that contains a decimal point Has minimum and maximum values Limited precision 4 is not the same as 4.0

Data Types and Variables Arithmetic Operators Lowest precedence to highest precedence + - * / // % **

Data Types and Variables String str A sequence of one or more characters A string of letters and numbers Enclosed in quotation marks Double quoted strings can contain single quotes and vice versa Triple quotes can span multiple lines

Data Types and Variables String Operators + * #

Data Types and Variables Variable = A name that refers to a value An assignment statement gives a value to a variable Variables remember things Variables can change, too = is Python s assignment token

Data Types and Variables Variable Names Can be of any length Characters must be letters, numbers, or the underscore (_) First character cannot be a number Case sensitive Python keywords cannot be used as variable names

Data Types and Variables Built-In Functions Multiple Assignment Assigning more than one variable at a time is possible a, b, c = 'foo', 'bar', 'baz' Swapping variable values x, y = y, x

Data Types and Variables Built-In Functions print()

Data Types and Variables Built-In Functions Built-In Functions A function is a reusable chunk of code We ve already been using functions print() int() type() Function name and arguments Parentheses mean execute this function Some functions take no input

Data Types and Variables Built-In Functions Modules A collection of related functions To use a module, it must be imported: import module Then you can use any of the functions in that module: module.function( ) You can also import all a module s functions at once: from module import * This allows you to call the function without appending the module

Data Types and Variables Built-In Functions Math Module Contains many useful mathematical functions Square root Pi Exponentiation Degree conversion Tangents

Data Types and Variables Built-In Functions Getting Help Python has lots of documentation built in Functions and modules usually come with brief explanations To list functions in a module: dir(module) To see all of Python s built-in functions: dir( builtins ) To get help with a specific function: help(function) Python s general help utility: help()

Writing Programs with Input and Output input()

Writing Programs with Input and Output Writing Programs A program is just a text file containing Python statements A program can have two lines of code or thousands Any plain text editor can be used although we will stick with IDLE Give your files the extension.py Python executes the file by running all the statements from top to bottom

Writing Programs with Input and Output Basic Input input() Reading strings from the keyboard Input function variable = input('prompt ') Input can be in the form of a string or numeric data type However, the value is always assigned to a variable as a string

Writing Programs with Input and Output Line Breaks for Long Statements Programming statements are normally written on one line If necessary, statements can be broken up into multiple lines with the line continuation character (backslash) print('this line and \ this line are connected.') \ must be placed at the end of the first line, before it is broken

Writing Programs with Input and Output More on the Print Function One of the most common functions we ve been using Important in our standalone Python programs for providing output Additional arguments to the print function include separator, end character Separator default sep = ' ' End character default end = '\n'

Writing Programs with Input and Output Escape Characters \n New line character \t Tab character \' Single quote character \" Double quote character \\ Backslash character

Writing Programs with Input and Output Formatting Numbers format() The format function allows you to format numbers, like floats Takes two arguments: the value to be formatted, and the format specification format(value, 'format_spec') The last number will also be rounded as appropriate

Control Structures Boolean Logic and If-Statements a b a == b a!= b a and b a or b not a

Control Structures Boolean Logic and If-Statements Boolean Logic Programming languages make decisions in binary terms Two boolean values: and and can be assigned to variables, just like strings and numbers Logical operators for boolean values: ==,!=, and, or, and not

Control Structures Boolean Logic and If-Statements Equivalence a == b Evaluates to when a and b are the same: Both a and b are Both a and b are

Control Structures Boolean Logic and If-Statements Negation a!= b Evaluates to when a and b are not the same: a is and b is a is and b is

Control Structures Boolean Logic and If-Statements And a and b Evaluates to when both a and b are : a is and b is

Control Structures Boolean Logic and If-Statements Or a or b Evaluates to when a is or b is : a is and b is a is and b is a is and b is

Control Structures Boolean Logic and If-Statements Not not a Evaluates to when a is and when a is : a is b is

Control Structures Boolean Logic and If-Statements Truth Table a b a == b a!= b a and b a or b not a

Control Structures Boolean Logic and If-Statements Order of Execution Highest to Lowest a == b a!= b not a a and b a or b

Control Structures Boolean Logic and If-Statements Conditional Statements Allow you to change the flow of a Python program Consist of if-statements Introduce code blocks

Control Structures Boolean Logic and If-Statements If/Else-Statements if else Begins with the keyword if Followed by a Boolean expression May be followed by an else block for alternate conditions

Control Structures Boolean Logic and If-Statements If/Else If-Statements if elif If-statement with more than one condition Multiple elif blocks are permitted else block is optional

Control Structures Boolean Logic and If-Statements Semantic Indentation Code blocks are meaningful in Python Indentation marks blocks of code and is not an optional format Code blocks must be indented consistently by the same amount As a result, Python code is clearer and more legible

Review Midterm Exam 1 Exam on Monday, October 7