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

Size: px
Start display at page:

Transcription

1 CS 115 Lecture 4 More Python; testing software Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky September 2015

2 Syntax: Statements A statement is the smallest unit of code that can be executed on its own. So far we ve seen: Assignment: sum = first + second Function call: print("hello") Usually one line, but compound statements can be bigger. def, for, if, etc. We ll see more of these in a few weeks. Comments aren t statements: they can t be executed. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

3 Syntax: Expressions An expression is a piece of code that has a value. It is an even smaller and more fundamental unit than the statement. Something you could use on the right hand side of assignment. Can be used as part of bigger expressions. Examples: Literals: 2, 3.4, "Python" Variable name: user name Arithmetic: 3 * (x + 2) (x + 2) is itself an expression... as are x and 2 It s expressions all the way down! Function call: input("what is your name?") Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

4 Semantics: Data types Inside the computer, everything is just bits. A data type says how to interpret those bits, and what we can do with them. Every expression in Python has a type. Some of the built-in types: Type Description Examples int integer numbers 2, -44 float floating-point numbers 3.0, -0.9, 6.022e23 bool Boolean (true-false) values True, False str strings of characters hello, "0" list lists of values [ "Valjean", ], [ 2, 3, 5, 7 ] Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

5 Integers Type int represents integers: whole numbers that may be positive, negative, or zero. Literal integers: a sequence of digits: with no leading zeros! 0 is okay, 007 is not. In Python, integers have no limit to their size. As many digits as you have memory for. That isn t true in most languages, like C++ and Java. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

6 Floating-point Type float represents floating-point numbers: numbers with a decimal point. Limited precision and range. Two forms of literal floats: Number with a decimal point: 3.14,.027, 0.001, 3., 1.0 Must have a decimal point! 1.0 or 1. is a float, but 1 is an integer! E -notation (scientific notation): 6.022e23, 1.0E9, 31e-2 Write e for times 10 to the Does not need a decimal point: the e is enough. Exponent must be an integer. In some languages these are called doubles Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

7 Floating-point limitations Floats are stored in a binary form of scientific notation: Mantissa: the digits (in binary). Exponent: how far to move the decimal (binary) point. In Python, the mantissa holds about 15 significant digits. Any digits past that are lost (rounding error). (leading and trailing zeros don t count) Limits the precision of a float. Try: Python s answer is 2.0: the 1 was rounded down! The exponent can go from about -300 to 300. Limits the range of a float. Try: 1e309 gives inf (infinity) Try: 1e-324 gives 0.0 The exact limits are on the number of bits, not digits. Even 0.1 can t be represented exactly Try: gives Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

8 Arithmetic on integers and floats You can perform arithmetic on both ints and floats. For most arithmetic operators (+ - * **) the rules are: If both operands are ints, the result is an int ** If one or both operand is a float, the result is a float ** e+30 There is one exception... What is 1/2? Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

9 Division Python actually has two division operators, / and //. / always gives a float. 1 / / / // does floor division: rounds the answer down to a whole number. If both operands are integers, so is the result. 22 // // 2 0 If either operand is a float, so is the result. But it still has a whole-number value. 22 // // In either case, dividing by zero is a run-time error! Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

10 Remainder (modulo) The % operator (modulo or mod) finds the remainder of a division. Between 0 (inclusive) and the right hand side (exclusive). 6 % % % % 3 0 Uses of modulo: Even/odd: n is even if n % 2 is zero. Digits: n % 10 is the last digit of n. Clock arithmetic Minutes are mod 60: 3: minutes = 4:13 Hours are mod 12: 10: hours = 2:00 Python can do modulo on floats. 5 % Far more common with ints, though. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

11 Booleans Type bool represents boolean values. Named after George Boole, English mathematician and logician. Exactly two values: True, False No quotes! They aren t strings. Case-sensitive as always: capital T and F. Boolean values are the basis of computer circuits: EE 280. Can t do arithmetic on them. Can do and, or, and not. Most often used with if and while statements. More about boolean operations in chapter 4. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

12 Strings Type str represents strings: sequences of characters. Literal strings: a sequence of characters in single or double quotes. hello, "world", "" Use whichever quote isn t in the string: some "quotes", "a postrophe" If you have to include the quote character, escape it with a backslash: msg = the word "don\ t" is 5 characters long Have to escape backslashes, too: folder = "C:\\Python 3.4" Special characters: tab \t, newline \n. Can perform a few operations on strings: Concatenate (join) strings with +: greeting = "Hello, " + name Repeat a string by multiplying with an integer: rating = * 4 # bird = 2 * do # dodo Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

13 Converting between types Converting between types is also called type casting. Write the name of the type you are converting to, then the expression to convert in parentheses: float(2) 2.0 int(3.14) 3 str(1.2e3) "1200.0" int("02") 2 float("0") 0.0 Converting double to int rounds towards zero (+ down, up) Run-time error if a string could not be converted: n = int("hello") # CRASHES with ValueError p = int("3.2") # CRASHES, but int(float("3.2")) is OK Converting a string does not do arithmetic: half = float("1/2") # CRASHES Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

14 Output: print Every program needs to do output of some kind: to the screen, a file, etc. In Python, we use the print function. Sends output to standard output. This is usually the shell window. Or the window that appears when you double-click a Python program. Syntax: print(arguments ) arguments is a comma-separated list of things to print. Can have zero, one, or more arguments. Each argument can be a literal, variable, expression,... Arguments can be any type: string, integer, float,... print("welcome to my program") print(6 * 7) print("hello", name) print() Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

15 Semantics of print Evaluates the arguments (computes their values). Prints values to standard output, starting at the cursor. If multiple arguments are given, puts a space between. Outputs a newline character at the end. Moves the cursor to the beginning of the next line. No-argument print() prints just a newline. The print function does not return a value. That means you can t (usefully) use it in an expression: x = print(2) # BAD This isn t a syntax error, but x s value will be None. Not very useful: usually a semantic error. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

16 Extra arguments to print Sometimes you don t want spaces between the arguments, or don t want a newline at the end. You can control these with so-called keyword arguments. sep=string : Use string to separate arguments instead of space. print(month, day, year, sep = "/") Might output: 1/27/2015 end=string : Print string at the end, not newline. That means the next print will start on the same line: print("the answer is", end=":") print(answer) Output: The answer is:42 Either string can be empty: print(f initial, m initial, l initial, sep= ) Output: NFM Can use both, but keyword arguments must come at the end! Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

17 Input Most programs also need to get input from the user. In Python we do this with input function. Syntax: input(prompt) One argument (unlike print) The argument is optional: input() Returns (evaluates to) a string. Usually used with assignment: name = input("what is your name? ") Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

18 Semantics of input The input function first prints the prompt. Without adding a newline! Usually ends in a space: name = input("what is your name? ") Include a newline \n to get input on its own line: name = input("what is your name?\n") If no prompt was given, prints nothing. Pauses the execution of the program, displays a blinking cursor. Waits for the user to press Enter. Returns the entire line of input. If the user pressed just Enter, returns an empty string. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

19 Using input The function returns a string value. Usually used as the right hand side of an assignment. name = input("what is your name? ") If you don t, throws away the input! input("press Enter to continue.") What if you need a number instead? Combine it with type casting! age = int(input("how old are you? ")) temp = float(input("what is the temperature? ")) What if the input cannot be converted? Run-time error (ValueError exception) Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

20 Testing We now know enough Python to write a simple program. But how do you know if the program works correctly? Testing! Verify that the progam: Gives the correct outputs. Doesn t crash unexpectedly. Doesn t run forever (infinite loop). For a four- or five-line program, could verify by inspection. But once it gets longer than that, needs systematic testing. Could plug in some random value and check the output. But what if we missed something? Need a plan... Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

21 Test cases We will test our programs by trying out a number of test cases. A typical test case has four parts: Description: what are you testing for? Input data you will give to the program. The expected output or outcome from that input. The actual output or outcome from that input. Do the first three parts before writing the program. Then fill out the actual output by running the program. In a software company, the last step is often done by dedicated testers (not the author). In CS 115, we ll usually omit the actual output. If it s different from the expected output, you have a bug. Fix the bugs before turning in the program. At the very least, document the bug with a comment. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

22 Test plan A test plan is a table with a number of test cases. Quality is more important than quantity! Test cases shouldn t overlap too much. If all your tests use positive numbers, how will you know whether negative numbers work? Making a good test plan requires thought and attention to the problem specifications. You should identify and test: Normal cases. Special cases. Boundary cases. Error cases. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

23 Sample test plan Suppose you are writing code for a vending machine. Inputs are quarters (Q, 25 cents), dollars (D, 100 cents), Coke button (C, costs 75 cents), and Refund button (R). Description Inputs Expected output Exact change Q Q Q C Vend one Coke. Inexact change D C - - Vend one Coke, return one quarter. Not enough Q Q C - Flash Continue Q C D C Flash 0.75, vend one Coke, return two quarters. Refund Q Q R - Return two quarters. Refund, no money R Do nothing. Even more test cases could be described... Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

24 Off-by-one errors You need to build a fence 100 feet long, with a fence post every 10 feet. How many posts do you need? Need 11, not 10! This is a common source of errors in programming. Fencepost errors or off-by-one errors. Whenever your program involves ranges (1 10, letters L R ): Test the boundary cases. Not just the endpoints, also adjacent numbers. So 0, 1, 2 (lower boundary), 9, 10, 11 (upper). K, L, M and Q, R, S. Why test boundary cases? It s easy to miss one endpoint. Or to go too far, past the endpoint. Make sure in-range inputs are accepted. Make sure out-of-range inputs are rejected. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

25 Regression testing What happens when you find a bug? When running your tests, you find an error on test 5. So you fix the bug in your program. Now what? Run test 5 again? Make sure you actually fixed it! What about tests 1 4? Those tests passed already, right? But what if your change broke something? A regression is when something used to work, but doesn t anymore. Because you (or Python, the OS,... ) changed something. How to avoid regressions? Regression testing: whenever you change the code, go back to the beginning and repeat all the tests. To make sure you didn t just add a bug too! This will save you points on CS 115 programs! Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

26 The end Next time: Libraries and the math library. Putting it all together: writing a complete program. Neil Moore (UK CS) CS 115 Lecture 4 Fall / 26

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

CS 115 Data Types and Arithmetic; Testing Taken from notes by Dr. Neil Moore Statements A statement is the smallest unit of code that can be executed on its own. So far we ve seen simple statements: Assignment:

### CS 115 Lecture 8. Selection: the if statement. Neil Moore

CS 115 Lecture 8 Selection: the if statement Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 24 September 2015 Selection Sometime we want to execute

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

Intro to Python Python Getting increasingly more common Designed to have intuitive and lightweight syntax In this class, we will be using Python 3.x Python 2.x is still very popular, and the differences

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

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

### Lecture 3. Input, Output and Data Types

Lecture 3 Input, Output and Data Types Goals for today Variable Types Integers, Floating-Point, Strings, Booleans Conversion between types Operations on types Input/Output Some ways of getting input, and

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

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### Lecture 1. Types, Expressions, & Variables

Lecture 1 Types, Expressions, & Variables About Your Instructor Director: GDIAC Game Design Initiative at Cornell Teach game design (and CS 1110 in fall) 8/29/13 Overview, Types & Expressions 2 Helping

### Programming for Engineers Introduction to C

Programming for Engineers Introduction to C ICEN 200 Spring 2018 Prof. Dola Saha 1 Simple Program 2 Comments // Fig. 2.1: fig02_01.c // A first program in C begin with //, indicating that these two lines

### cs1114 REVIEW of details test closed laptop period

python details DOES NOT COVER FUNCTIONS!!! This is a sample of some of the things that you are responsible for do not believe that if you know only the things on this test that they will get an A on any

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

1 Professor: Sana Odeh odeh@courant.nyu.edu Lecture 3 Python 3.1 Variables, Primitive Data Types & arithmetic operators Review What s wrong with this line of code? print( He said Hello ) What s wrong with

### Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

### A Java program contains at least one class definition.

Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

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

COMP1730/COMP6730 Programming for Scientists Data: Values, types and expressions. Lecture outline * Data and data types. * Expressions: computing values. * Variables: remembering values. What is data?

### Getting Started Values, Expressions, and Statements CS GMU

Getting Started Values, Expressions, and Statements CS 112 @ GMU Topics where does code go? values and expressions variables and assignment 2 where does code go? we can use the interactive Python interpreter

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

Overview - General Data Types - Categories of Words - The Three S s - Define Before Use - End of Statement - My First Program a description of data, defining a set of valid values and operations List of

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

### Intro 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

### COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

COSC 243 Data Representation 3 Lecture 3 - Data Representation 3 1 Data Representation Test Material Lectures 1, 2, and 3 Tutorials 1b, 2a, and 2b During Tutorial a Next Week 12 th and 13 th March If you

### Python Day 3 11/28/16

Python Day 3 11/28/16 Objectives Review Concepts Types of Errors Escape sequences String functions Find the Errors bookcost = int(input("how much is the book: ")) discount = float(input("what is the discount:

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

Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

### Full file at

Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

### CS61B Lecture #14: Integers. Last modified: Wed Sep 27 15:44: CS61B: Lecture #14 1

CS61B Lecture #14: Integers Last modified: Wed Sep 27 15:44:05 2017 CS61B: Lecture #14 1 Integer Types and Literals Type Bits Signed? Literals byte 8 Yes Cast from int: (byte) 3 short 16 Yes None. Cast

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

Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

### Introduction to Computation for the Humanities and Social Sciences. CS 3 Chris Tanner

Introduction to Computation for the Humanities and Social Sciences CS 3 Chris Tanner Lecture 4 Python: Variables, Operators, and Casting Lecture 4 [People] need to learn code, man I m sick with the Python.

### Python 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

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

Python The way of a program Srinidhi H Asst Professor Dept of CSE, MSRIT 1 Problem Solving Problem solving means the ability to formulate problems, think creatively about solutions, and express a solution

### Introduction to Scientific Computing Lecture 1

Introduction to Scientific Computing Lecture 1 Professor Hanno Rein Last updated: September 10, 2017 1 Number Representations In this lecture, we will cover two concept that are important to understand

### Advanced Algorithms and Computational Models (module A)

Advanced Algorithms and Computational Models (module A) Giacomo Fiumara giacomo.fiumara@unime.it 2014-2015 1 / 34 Python's built-in classes A class is immutable if each object of that class has a xed value

### 2 nd Week Lecture Notes

2 nd Week Lecture Notes Scope of variables All the variables that we intend to use in a program must have been declared with its type specifier in an earlier point in the code, like we did in the previous

### Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

Assoc. Prof. Dr. Marenglen Biba (C) 2010 Pearson Education, Inc. All rights reserved. Java application A computer program that executes when you use the java command to launch the Java Virtual Machine

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

2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

### Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

### CMSC 201 Fall 2016 Lab 09 Advanced Debugging

CMSC 201 Fall 2016 Lab 09 Advanced Debugging Assignment: Lab 09 Advanced Debugging Due Date: During discussion Value: 10 points Part 1: Introduction to Errors Throughout this semester, we have been working

### Chapter 2 Getting Started with Python

Chapter 2 Getting Started with Python Introduction Python Programming language was developed by Guido Van Rossum in February 1991. It is based on or influenced with two programming languages: 1. ABC language,

### BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

### Here n is a variable name. The value of that variable is 176.

UNIT II DATA, EXPRESSIONS, STATEMENTS 9 Python interpreter and interactive mode; values and types: int, float, boolean, string, and list; variables, expressions, statements, tuple assignment, precedence

### CS112 Lecture: Primitive Types, Operators, Strings

CS112 Lecture: Primitive Types, Operators, Strings Last revised 1/24/06 Objectives: 1. To explain the fundamental distinction between primitive types and reference types, and to introduce the Java primitive

### SSEA Computer Science: Track A. Dr. Cynthia Lee Lecturer in Computer Science Stanford

SSEA Computer Science: Track A Dr. Cynthia Lee Lecturer in Computer Science Stanford Topics for today Introduce Java programming language Assignment and type casting Expressions Operator precedence Code

### C++ Data Types. 1 Simple C++ Data Types 2. 3 Numeric Types Integers (whole numbers) Decimal Numbers... 5

C++ Data Types Contents 1 Simple C++ Data Types 2 2 Quick Note About Representations 3 3 Numeric Types 4 3.1 Integers (whole numbers)............................................ 4 3.2 Decimal Numbers.................................................

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

CS95003 - Applied Robotics Lab Gerardo Carmona :: makeroboticsprojects.com June / 2014 Subjects 1) Beginning with Python 2) Variables 3) Strings 4) Basic arithmetic operators 5) Flow control 6) Comparison

### Problem Solving for Intro to Computer Science

Problem Solving for Intro to Computer Science The purpose of this document is to review some principles for problem solving that are relevant to Intro to Computer Science course. Introduction: A Sample

### Variables, Constants, and Data Types

Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types

### Fundamentals: Expressions and Assignment

Fundamentals: Expressions and Assignment A typical Python program is made up of one or more statements, which are executed, or run, by a Python console (also known as a shell) for their side effects e.g,

### Getting 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?

### CS61B Lecture #14: Integers

Announcement: CS61B Lecture #14: Integers Project #0 due Tuesday night. Programming contest SATURDAY! You can still sign up at https://inst.eecs.berkeley.edu/~ctest/contest/register. Test #1 will be Tuesday,

More about Binary 9/6/2016 Unsigned vs. Two s Complement 8-bit example: 1 1 0 0 0 0 1 1 2 7 +2 6 + 2 1 +2 0 = 128+64+2+1 = 195-2 7 +2 6 + 2 1 +2 0 = -128+64+2+1 = -61 Why does two s complement work this

### C: How to Program. Week /Mar/05

1 C: How to Program Week 2 2007/Mar/05 Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers

### First Java Program - Output to the Screen

First Java Program - Output to the Screen These notes are written assuming that the reader has never programmed in Java, but has programmed in another language in the past. In any language, one of the

### Introduction to Python

Introduction to Python Reading assignment: Perkovic text, Ch. 1 and 2.1-2.5 Python Python is an interactive language. Java or C++: compile, run Also, a main function or method Python: type expressions

Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style 3 2.1 Variables and Assignments Variables and

### Fundamentals of Programming Session 4

Fundamentals of Programming Session 4 Instructor: Reza Entezari-Maleki Email: entezari@ce.sharif.edu 1 Fall 2011 These slides are created using Deitel s slides, ( 1992-2010 by Pearson Education, Inc).

### Overview: Programming Concepts. Programming Concepts. Names, Values, And Variables

Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

### Overview: Programming Concepts. Programming Concepts. Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript

Chapter 18: Get With the Program: Fundamental Concepts Expressed in JavaScript Fluency with Information Technology Third Edition by Lawrence Snyder Overview: Programming Concepts Programming: Act of formulating

### CSE 115. Introduction to Computer Science I

CSE 115 Introduction to Computer Science I Note about posted slides The slides we post will sometimes contain additional slides/content, beyond what was presented in any one lecture. We do this so the

### 3 The Building Blocks: Data Types, Literals, and Variables

chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

### CS 115 Lecture 13. Strings. Neil Moore. Department of Computer Science University of Kentucky Lexington, Kentucky

CS 115 Lecture 13 Strings Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 29 October 2015 Strings We ve been using strings for a while. What can

### A First Look at ML. Chapter Five Modern Programming Languages, 2nd ed. 1

A First Look at ML Chapter Five Modern Programming Languages, 2nd ed. 1 ML Meta Language One of the more popular functional languages (which, admittedly, isn t saying much) Edinburgh, 1974, Robin Milner

### Built-in Types of Data

Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),

### COMS 1003 Fall Introduction to Computer Programming in C. Bits, Boolean Logic & Discrete Math. September 13 th

COMS 1003 Fall 2005 Introduction to Computer Programming in C Bits, Boolean Logic & Discrete Math September 13 th Hello World! Logistics See the website: http://www.cs.columbia.edu/~locasto/ Course Web

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

Plan for the rest of the semester: Programming We will be introducing various new elements of Python and using them to solve increasingly interesting and complex problems. We saw earlier that computers

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

Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

### Full file at C How to Program, 6/e Multiple Choice Test Bank

2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

### Computer Science 121. Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans

Computer Science 121 Scientific Computing Winter 2016 Chapter 3 Simple Types: Numbers, Text, Booleans 3.1 The Organization of Computer Memory Computers store information as bits : sequences of zeros and

### C++ Programming: From Problem Analysis to Program Design, Third Edition

C++ Programming: From Problem Analysis to Program Design, Third Edition Chapter 2: Basic Elements of C++ Objectives (continued) Become familiar with the use of increment and decrement operators Examine

### AP Computer Science A

AP Computer Science A 1st Quarter Notes Table of Contents - section links Click on the date or topic below to jump to that section Date : 9/8/2017 Aim : Java Basics Objects and Classes Data types: Primitive

### Text 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()

Chapter 2 C++ Basics 1 Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-3 2.1 Variables and Assignments 2

### Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Python for Analytics Python Fundamentals RSI Chapters 1 and 2 Learning Objectives Theory: You should be able to explain... General programming terms like source code, interpreter, compiler, object code,

### Ex: If you use a program to record sales, you will want to remember data:

Data Variables Programs need to remember values. Ex: If you use a program to record sales, you will want to remember data: A loaf of bread was sold to Sione Latu on 14/02/19 for T\$1.00. Customer Name:

### Chapter 2. C++ Basics

Chapter 2 C++ Basics Overview 2.1 Variables and Assignments 2.2 Input and Output 2.3 Data Types and Expressions 2.4 Simple Flow of Control 2.5 Program Style Slide 2-2 2.1 Variables and Assignments Variables

### Objectives. In this chapter, you will:

Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

### MIT 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

### CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS113: Lecture 3 Topics: Variables Data types Arithmetic and Bitwise Operators Order of Evaluation 1 Variables Names of variables: Composed of letters, digits, and the underscore ( ) character. (NO spaces;

### Lecture 1. Course Overview, Python Basics

Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures and Labs are at fire-code capacity We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are

### Chapter 17. Fundamental Concepts Expressed in JavaScript

Chapter 17 Fundamental Concepts Expressed in JavaScript Learning Objectives Tell the difference between name, value, and variable List three basic data types and the rules for specifying them in a program

### IT 374 C# and Applications/ IT695 C# Data Structures

IT 374 C# and Applications/ IT695 C# Data Structures Module 2.1: Introduction to C# App Programming Xianrong (Shawn) Zheng Spring 2017 1 Outline Introduction Creating a Simple App String Interpolation

### ENGR 102 Engineering Lab I - Computation

ENGR 102 Engineering Lab I - Computation Week 03: Data Types and Console Input / Output Introduction to Types As we have already seen, 1 computers store numbers in a binary sequence of bits. The organization

### These are notes for the third lecture; if statements and loops.

These are notes for the third lecture; if statements and loops. 1 Yeah, this is going to be the second slide in a lot of lectures. 2 - Dominant language for desktop application development - Most modern

### Module 1: Types and Expressions

Module 1: Types and Expressions Ron K. Cytron * Department of Computer Science and Engineering * Washington University in Saint Louis Thanks to Alan Waldman for comments that improved these slides Prepared

### Monty Python and the Holy Grail (1975) BBM 101. Introduction to Programming I. Lecture #03 Introduction to Python and Programming, Control Flow

BBM 101 Monty Python and the Holy Grail (1975) Introduction to Programming I Lecture #03 Introduction to Python and Programming, Control Flow Aykut Erdem, Fuat Akal & Aydın Kaya // Fall 2018 Last time

### Variables, 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

### Unit 3. Constants and Expressions

1 Unit 3 Constants and Expressions 2 Review C Integer Data Types Integer Types (signed by default unsigned with optional leading keyword) C Type Bytes Bits Signed Range Unsigned Range [unsigned] char 1

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

PRG PROGRAMMING ESSENTIALS 1 Lecture 2 Program flow, Conditionals, Loops https://cw.fel.cvut.cz/wiki/courses/be5b33prg/start Michal Reinštein Czech Technical University in Prague, Faculty of Electrical

### Lecture 1. Course Overview, Python Basics

Lecture 1 Course Overview, Python Basics We Are Very Full! Lectures are at fire-code capacity. We cannot add sections or seats to lectures You may have to wait until someone drops No auditors are allowed

### CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

### 2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Chapter 2: Introduction to C++ 2.1 Parts of a C++ Program Copyright 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 2-1 Parts of a C++ Program Parts of a C++ Program // sample C++ program

### 7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

### Conditionals and Recursion. Python Part 4

Conditionals and Recursion Python Part 4 Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print (remainder) 1 Boolean expressions An expression that

### Strings and Testing string methods, formatting testing approaches CS GMU

Strings and Testing string methods, formatting testing approaches CS 112 @ GMU Topics string methods string formatting testing, unit testing 2 Some String Methods (See LIB 4.7.1) usage: stringexpr. methodname

### Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will

### Lecture Numbers. Richard E Sarkis CSC 161: The Art of Programming

Lecture Numbers Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To understand the concept of data types To be familiar with the basic numeric data types in Python To be able

### Chapter 2 - Introduction to C Programming

Chapter 2 - Introduction to C Programming 2 Outline 2.1 Introduction 2.2 A Simple C Program: Printing a Line of Text 2.3 Another Simple C Program: Adding Two Integers 2.4 Memory Concepts 2.5 Arithmetic

### >>> * *(25**0.16) *10*(25**0.16)

#An Interactive Session in the Python Shell. #When you type a statement in the Python Shell, #the statement is executed immediately. If the #the statement is an expression, its value is #displayed. #Lines

### Foundations of Computer Systems

18-600 Foundations of Computer Systems Lecture 4: Floating Point Required Reading Assignment: Chapter 2 of CS:APP (3 rd edition) by Randy Bryant & Dave O Hallaron Assignments for This Week: Lab 1 18-600

### Getting 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