Lecture 4: Basic I/O

Size: px
Start display at page:

Download "Lecture 4: Basic I/O"

Transcription

1 Lecture 4: Basic I/O CS1068+ Introductory Programming in Python Dr Kieran T. Herley Department of Computer Science University College Cork KH (21/09/17) Lecture 4: Basic I/O / 20

2 Summary Data type string. Basic I/O using print and input. Simple input-calculate-output programs. KH (21/09/17) Lecture 4: Basic I/O / 20

3 Data type str String basics Strings are sequences of characters (letters, digits, symbols and so on) and are used to represent textual snippets (among other things) KH (21/09/17) Lecture 4: Basic I/O / 20

4 Data type str String basics Strings are sequences of characters (letters, digits, symbols and so on) and are used to represent textual snippets (among other things) Examples: "" "President" "Barack Obama" "1600 Pensylvania Avenue, Washington DC, USA" " " "cs1068 is $#?%!" Double quotes delimit string (but are not part of it.) KH (21/09/17) Lecture 4: Basic I/O / 20

5 Data type str Printing strings Use print function: >>> KH (21/09/17) Lecture 4: Basic I/O / 20

6 Data type str Printing strings Use print function: >>>print("barack Obama") KH (21/09/17) Lecture 4: Basic I/O / 20

7 Data type str Printing strings Use print function: >>>print("barack Obama") Barack Obama Note: Enclosing quotes not printed (not part of string) KH (21/09/17) Lecture 4: Basic I/O / 20

8 Data type str More on string literals We can also use single quotes to delimit strings Only 97 days to Christmas! We prefer doubles, but both are legal KH (21/09/17) Lecture 4: Basic I/O / 20

9 Data type str More on string literals We can also use single quotes to delimit strings Only 97 days to Christmas! We prefer doubles, but both are legal We can also use treble quotes (single or double) for multi-line strings """ There was a young student from Cork You tried Python for a lark But as hard as be tried His brain it did fry And he struggled to come up to the mark! """ KH (21/09/17) Lecture 4: Basic I/O / 20

10 Data type str Including tricky characters strings What if we need to represent a string that itself contains a double quote character? Escape the internal quote symbol by preceding it with backslash : >>>print("barack says, \"Python rocks!\"") Barack says, "Python rocks!" The two-character combination \ produces the single symbol Other awkward characters: \\ backslash \ single quote \ double quote \n newline \t tab KH (21/09/17) Lecture 4: Basic I/O / 20

11 Data type str Basic string manipulation Concatenation Can join(concatenate) strings together using +: "Santa"+"Claus"! $\rightarrow$ \verb!"santaclaus" Repetition Can repeat strings together using so "Wibble! $\rightarrow$ Wibble! Wibble! "Santa says"+3*" ho"! $\rightarrow$ \verb!"santa says ho ho ho NB Operators + and valid with both integers and strings but with different meaning KH (21/09/17) Lecture 4: Basic I/O / 20

12 Data type str Basic string conversions Need to be careful when working with different types >>> KH (21/09/17) Lecture 4: Basic I/O / 20

13 Data type str Basic string conversions Need to be careful when working with different types >>>x = "123" KH (21/09/17) Lecture 4: Basic I/O / 20

14 Data type str Basic string conversions Need to be careful when working with different types >>>x = "123" >>> KH (21/09/17) Lecture 4: Basic I/O / 20

15 Data type str Basic string conversions Need to be careful when working with different types >>>x = "123" >>>y = x + 1 KH (21/09/17) Lecture 4: Basic I/O / 20

16 Data type str Basic string conversions Need to be careful when working with different types >>>x = "123" >>>y = x + 1 Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> x + 1 TypeError: Can t convert int object to str implicitly Use int function to explicitly convert string 123 into corresponding integer (123); use float for string to float conversions; string must be numerical error otherwise KH (21/09/17) Lecture 4: Basic I/O / 20

17 Data type str String conversions con t >>> KH (21/09/17) Lecture 4: Basic I/O / 20

18 Data type str String conversions con t >>>x = "123" KH (21/09/17) Lecture 4: Basic I/O / 20

19 Data type str String conversions con t >>>x = "123" >>> KH (21/09/17) Lecture 4: Basic I/O / 20

20 Data type str String conversions con t >>>x = "123" >>>y = int(x) + 1 KH (21/09/17) Lecture 4: Basic I/O / 20

21 Data type str String conversions con t >>>x = "123" >>>y = int(x) + 1 >>> KH (21/09/17) Lecture 4: Basic I/O / 20

22 Data type str String conversions con t >>>x = "123" >>>y = int(x) + 1 >>>print(y) KH (21/09/17) Lecture 4: Basic I/O / 20

23 Data type str String conversions con t >>>x = "123" >>>y = int(x) + 1 >>>print(y) 124 For int-to-string use str function i.e. str(123) is 123 KH (21/09/17) Lecture 4: Basic I/O / 20

24 Using the print statement Basic print capabilities >>>print(17) 17 >>>x = 23 >>>print(x) 23 >>>print("hello") Hello >>>print("x is ", x) x is 17 Single print can handle multiple items Each print generates newline once it s finished (by default) KH (21/09/17) Lecture 4: Basic I/O / 20

25 Using input statement Operation of input function Use input function to gather data from user >>> KH (21/09/17) Lecture 4: Basic I/O / 20

26 Using input statement Operation of input function Use input function to gather data from user >>>x = input("please type something: ") KH (21/09/17) Lecture 4: Basic I/O / 20

27 Using input statement Operation of input function Use input function to gather data from user >>>x = input("please type something: ") Please type something: KH (21/09/17) Lecture 4: Basic I/O / 20

28 Using input statement Operation of input function Use input function to gather data from user >>>x = input("please type something: ") Please type something: Wibble! >>> KH (21/09/17) Lecture 4: Basic I/O / 20

29 Using input statement Operation of input function Use input function to gather data from user >>>x = input("please type something: ") Please type something: Wibble! >>>print(x) KH (21/09/17) Lecture 4: Basic I/O / 20

30 Using input statement Operation of input function Use input function to gather data from user >>>x = input("please type something: ") Please type something: Wibble! >>>print(x) Wibble! The prompt ( Please... ) displayed to nudge user to type something (System pauses until user types something and hits Enter) entire line typed in by user is read in entire line (minus trailing newline) interpreted as a string name x is attached to this string KH (21/09/17) Lecture 4: Basic I/O / 20

31 Using input statement Simple example 1 >>> KH (21/09/17) Lecture 4: Basic I/O / 20

32 Using input statement Simple example 1 >>>fav = input("what is your favourite colour? ") KH (21/09/17) Lecture 4: Basic I/O / 20

33 Using input statement Simple example 1 >>>fav = input("what is your favourite colour? ") What is your favourite colour? KH (21/09/17) Lecture 4: Basic I/O / 20

34 Using input statement Simple example 1 >>>fav = input("what is your favourite colour? ") What is your favourite colour? Grey >>> KH (21/09/17) Lecture 4: Basic I/O / 20

35 Using input statement Simple example 1 >>>fav = input("what is your favourite colour? ") What is your favourite colour? Grey >>>print("you typed ", fav) KH (21/09/17) Lecture 4: Basic I/O / 20

36 Using input statement Simple example 1 >>>fav = input("what is your favourite colour? ") What is your favourite colour? Grey >>>print("you typed ", fav) You typed Grey KH (21/09/17) Lecture 4: Basic I/O / 20

37 Using input statement Simple example 1 >>>fav = input("what is your favourite colour? ") What is your favourite colour? Grey >>>print("you typed ", fav) You typed Grey Note: No check that user entered anything sensible KH (21/09/17) Lecture 4: Basic I/O / 20

38 Using input statement Simple example 2 Enhanced version of temperature conversion code that asks users for Celsius temp First attempt: >>>temp c = input("please enter... ") KH (21/09/17) Lecture 4: Basic I/O / 20

39 Using input statement Simple example 2 Enhanced version of temperature conversion code that asks users for Celsius temp First attempt: >>>temp c = input("please enter... ") Please enter temp. (Celsius) KH (21/09/17) Lecture 4: Basic I/O / 20

40 Using input statement Simple example 2 Enhanced version of temperature conversion code that asks users for Celsius temp First attempt: >>>temp c = input("please enter... ") Please enter temp. (Celsius) 17 >>>temp f = temp c * 9 / KH (21/09/17) Lecture 4: Basic I/O / 20

41 Using input statement Diagnosis: temp c is a string KH (21/09/17) Lecture 4: Basic I/O / 20 Simple example 2 Enhanced version of temperature conversion code that asks users for Celsius temp First attempt: >>>temp c = input("please enter... ") Please enter temp. (Celsius) 17 >>>temp f = temp c * 9 / Traceback (most recent call last File "/home/kieran/work/teaching/python/code/examples/tempconv line 5, in <modul temp f = temp c * 9 / TypeError: unsupported operand type(s) for /: str and int

42 Using input statement Simple example 2 Corrected version >>>temp c = float(input("please enter...")) Please enter temp. (Celsius) KH (21/09/17) Lecture 4: Basic I/O / 20

43 Using input statement Simple example 2 Corrected version >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 >>>temp f = temp c * 9 / >>>print("fahrenheit equivalent is ", temp f) Fahrenheit equivalent is 62.6 KH (21/09/17) Lecture 4: Basic I/O / 20

44 Using input statement Simple example 2 Corrected version slow motion >>> KH (21/09/17) Lecture 4: Basic I/O / 20

45 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) KH (21/09/17) Lecture 4: Basic I/O / 20

46 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius) KH (21/09/17) Lecture 4: Basic I/O / 20

47 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 KH (21/09/17) Lecture 4: Basic I/O / 20

48 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 >>> KH (21/09/17) Lecture 4: Basic I/O / 20

49 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 >>>temp f = temp c * 9 / KH (21/09/17) Lecture 4: Basic I/O / 20

50 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 >>>temp f = temp c * 9 / >>> KH (21/09/17) Lecture 4: Basic I/O / 20

51 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 >>>temp f = temp c * 9 / >>>print("fahrenheit equivalent is ", temp f) KH (21/09/17) Lecture 4: Basic I/O / 20

52 Using input statement Simple example 2 Corrected version slow motion >>>temp c = float(input("please enter...")) Please enter temp. (Celsius)17 >>>temp f = temp c * 9 / >>>print("fahrenheit equivalent is ", temp f) Fahrenheit equivalent is 62.6 KH (21/09/17) Lecture 4: Basic I/O / 20

53 Using the IDLE program editor The program editor So far we have entered programs one line at at time Far more common (and convenient) to compose complete program in IDLE s program editor Can run programs ( Run menu option) from here Output appears in command shell KH (21/09/17) Lecture 4: Basic I/O / 20

54 Using the IDLE program editor Executing programs from text editor Left: IDLE shell; Right: editor with temperature converter program KH (21/09/17) Lecture 4: Basic I/O / 20

55 Using the IDLE program editor Once Run is clicked, program is translated and executed; any I/O appears in shell KH (21/09/17) Lecture 4: Basic I/O / 20 Executing programs from text editor cont d

56 Using the IDLE program editor What the output looks like Python (default, Apr , 13:05:18) [GCC 4.8.2] on linux Type "copyright", "credits".... ================================================== >>> Enter temp (Celsius): 23 Equivalent in Fahrenheit is 73.4 >>> KH (21/09/17) Lecture 4: Basic I/O / 20

57 Back Material Notes and Acknowledgements Reading Code Acknowledgements KH (21/09/17) Lecture 4: Basic I/O / 20

Lecture 10: Strings. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork

Lecture 10: Strings. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork Lecture 10: Strings CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2018/19 Department of Computer Science University College Cork Summary 1 Python text: data type str String sequences of

More information

Lecture 4: Simple Input-Calculate-Output Programs

Lecture 4: Simple Input-Calculate-Output Programs Lecture 4: Simple Input-Calculate-Output Programs CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2017/18 Department of Computer Science University College Cork input Statement Python s

More information

Not-So-Mini-Lecture 6. Modules & Scripts

Not-So-Mini-Lecture 6. Modules & Scripts Not-So-Mini-Lecture 6 Modules & Scripts Interactive Shell vs. Modules Launch in command line Type each line separately Python executes as you type Write in a code editor We use Atom Editor But anything

More information

Getting Started Values, Expressions, and Statements CS GMU

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

More information

Fundamentals of Programming (Python) Getting Started with Programming

Fundamentals of Programming (Python) Getting Started with Programming Fundamentals of Programming (Python) Getting Started with Programming Ali Taheri Sharif University of Technology Some slides have been adapted from Python Programming: An Introduction to Computer Science

More information

Getting Started with Python

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

More information

Introduction to Python

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

More information

Lecture 2: Python Arithmetic

Lecture 2: Python Arithmetic Lecture 2: Python Arithmetic CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2018/19 Department of Computer Science University College Cork Basic data types in Python Python data types Programs

More information

Table of Contents Date(s) Title/Topic Page #s. Abstraction

Table of Contents Date(s) Title/Topic Page #s. Abstraction Table of Contents Date(s) Title/Topic Page #s 9/10 2.2 String Literals, 2.3 Variables and Assignment 34-35 Abstraction An abstraction hides (or suppresses) the right details at the right time An object

More information

ENGR 101 Engineering Design Workshop

ENGR 101 Engineering Design Workshop ENGR 101 Engineering Design Workshop Lecture 2: Variables, Statements/Expressions, if-else Edgardo Molina City College of New York Literals, Variables, Data Types, Statements and Expressions Python as

More information

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

CS 115 Lecture 4. More Python; testing software. Neil Moore CS 115 Lecture 4 More Python; testing software Neil Moore Department of Computer Science University of Kentucky Lexington, Kentucky 40506 neil@cs.uky.edu 8 September 2015 Syntax: Statements A statement

More information

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal

Hello, World! An Easy Intro to Python & Programming. Jack Rosenthal An Easy Intro to Python & Programming Don t just buy a new video game, make one. Don t just download the latest app, help design it. Don t just play on your phone, program it. No one is born a computer

More information

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. - 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

More information

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

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

More information

When you open IDLE (Version 3.2.2) for the first time, you're presented with the following window:

When you open IDLE (Version 3.2.2) for the first time, you're presented with the following window: (Python) Chapter 1: Introduction to Programming in Python 1.1 Compiled vs. Interpreted Languages Computers only understand 0s and 1s, their native machine language. All of the executable programs on your

More information

Python Class-Lesson1 Instructor: Yao

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

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

Lecture 4. Defining Functions

Lecture 4. Defining Functions Lecture 4 Defining Functions Academic Integrity Quiz Reading quiz about the course AI policy Go to http://www.cs.cornell.edu/courses/cs11110/ Click Academic Integrity in side bar Read and take quiz in

More information

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007 Course Web Site http://www.nps.navy.mil/cs/facultypages/squire/cs2900 All course related materials will be posted

More information

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

Lab 1: Course Intro, Getting Started with Python IDLE. Ling 1330/2330 Computational Linguistics Na-Rae Han Lab 1: Course Intro, Getting Started with Python IDLE Ling 1330/2330 Computational Linguistics Na-Rae Han Objectives Course Introduction http://www.pitt.edu/~naraehan/ling1330/index.html Student survey

More information

Lecture 10: Boolean Expressions

Lecture 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 information

Chapter 2 Writing Simple Programs

Chapter 2 Writing Simple Programs Chapter 2 Writing Simple Programs Charles Severance Textbook: Python Programming: An Introduction to Computer Science, John Zelle (www.si182.com) Software Development Process Figure out the problem - for

More information

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

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

More information

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi

CMPT 120 Basics of Python. Summer 2012 Instructor: Hassan Khosravi CMPT 120 Basics of Python Summer 2012 Instructor: Hassan Khosravi Python A simple programming language to implement your ideas Design philosophy emphasizes code readability Implementation of Python was

More information

Full file at

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

More information

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

Python Input, output and variables. Lecture 23 COMPSCI111/111G SS 2018 Python Input, output and variables Lecture 23 COMPSCI111/111G SS 2018 1 Today s lecture What is Python? Displaying text on screen using print() Variables Numbers and basic arithmetic Getting input from

More information

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

More information

Lecture 3. Input, Output and Data Types

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

More information

Introduction to Python and Programming. 1. Python is Like a Calculator. You Type Expressions. Python Computes Their Values /2 2**3 3*4+5*6

Introduction to Python and Programming. 1. Python is Like a Calculator. You Type Expressions. Python Computes Their Values /2 2**3 3*4+5*6 1. Python is a calculator. A variable is a container Introduction to Python and Programming BBM 101 - Introduction to Programming I Hacettepe University Fall 016 Fuat Akal, Aykut Erdem, Erkut Erdem 3.

More information

CS112 Lecture: Primitive Types, Operators, Strings

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

More information

Chapter 2 Getting Started with Python

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,

More information

PYTHON. Values and Variables

PYTHON. Values and Variables December 13 2017 Naveen Sagayaselvaraj PYTHON Values and Variables Overview Integer Values Variables and Assignment Identifiers Floating-point Types User Input The eval Function Controlling the print Function

More information

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2 Basic Concepts Computer Science Computer - Science - Programming history Algorithms Pseudo code 2013 Andrew Case 2 Basic Concepts Computer Science Computer a machine for performing calculations Science

More information

Lecture 2: SQL Basics

Lecture 2: SQL Basics Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (19/09/17) Lecture 2: SQL Basics

More information

Algorithms and Programming I. Lecture#12 Spring 2015

Algorithms and Programming I. Lecture#12 Spring 2015 Algorithms and Programming I Lecture#12 Spring 2015 Think Python How to Think Like a Computer Scientist By :Allen Downey Installing Python Follow the instructions on installing Python and IDLE on your

More information

Programming for Engineers in Python. Recitation 1

Programming for Engineers in Python. Recitation 1 Programming for Engineers in Python Recitation 1 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional

More information

Variables, Constants, and Data Types

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

More information

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

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

More information

Constants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter

Constants. Variables, Expressions, and Statements. Variables. x = 12.2 y = 14 x = 100. Chapter Variables, Expressions, and Statements Chapter 2 Unless otherwise noted, the content of this course material is licensed under a Creative Commons Attribution 3.0 License. http://creativecommons.org/licenses/by/3.0/.

More information

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

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

More information

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on: Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

More information

Python Input, output and variables

Python Input, output and variables Today s lecture Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016! What is Python?! Displaying text on screen using print()! Variables! Numbers and basic arithmetic! Getting input from

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

More information

Python Unit

Python Unit Python Unit 1 1.1 1.3 1.1: OPERATORS, EXPRESSIONS, AND VARIABLES 1.2: STRINGS, FUNCTIONS, CASE SENSITIVITY, ETC. 1.3: OUR FIRST TEXT- BASED GAME Python Section 1 Text Book for Python Module Invent Your

More information

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

Python Input, output and variables. Lecture 22 COMPSCI111/111G SS 2016 Python Input, output and variables Lecture 22 COMPSCI111/111G SS 2016 Today s lecture u What is Python? u Displaying text on screen using print() u Variables u Numbers and basic arithmetic u Getting input

More information

Lecture Writing Programs. Richard E Sarkis CSC 161: The Art of Programming

Lecture Writing Programs. Richard E Sarkis CSC 161: The Art of Programming Lecture Writing Programs Richard E Sarkis CSC 161: The Art of Programming Class Administrivia Agenda To be able to understand and write Python statements to output information to the screen To assign values

More information

Programming in Python 3

Programming in Python 3 Programming in Python 3 Programming transforms your computer from a home appliance to a power tool Al Sweigart, The invent with Python Blog Programming Introduction Write programs that solve a problem

More information

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

\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

More information

Introduction to Bioinformatics

Introduction 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 information

Variable and Data Type I

Variable and Data Type I Islamic University Of Gaza Faculty of Engineering Computer Engineering Department Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad September 24, 2016 Variable is reserved a location in memory to store

More information

Simple Lexical Analyzer

Simple Lexical Analyzer Lecture 7: Simple Lexical Analyzer Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (03/10/17) Lecture 7: Simple Lexical Analyzer 2017-2018 1 / 1 Summary Use of jflex

More information

MEIN 50010: Python Introduction

MEIN 50010: Python Introduction : Python Fabian Sievers Higgins Lab, Conway Institute University College Dublin Wednesday, 2017-10-04 Outline Goals Teach basic programming concepts Apply these concepts using Python Use Python Packages

More information

Programming for Engineers in Python. Autumn

Programming for Engineers in Python. Autumn Programming for Engineers in Python Autumn 2011-12 Plan Administration: Course site Homework submission guidelines Working environment Python: Variables Editor vs. shell Homework 0 Python Cont. Conditional

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/58 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

Intro to Python & Programming. C-START Python PD Workshop

Intro to Python & Programming. C-START Python PD Workshop Don t just buy a new video game, make one. Don t just download the latest app, help design it. Don t just play on your phone, program it. No one is born a computer scientist, but with a little hard work

More information

SI Networked Computing: Storage, Communication, and Processing, Winter 2009

SI Networked Computing: Storage, Communication, and Processing, Winter 2009 University of Michigan Deep Blue deepblue.lib.umich.edu 2009-01 SI 502 - Networked Computing: Storage, Communication, and Processing, Winter 2009 Severance, Charles Severance, C. (2008, December 19). Networked

More information

Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Brief Note on Naming Conventions. Our Running Example.

Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases. Brief Note on Naming Conventions. Our Running Example. Lecture 2: SQL Basics CS1106/CS5021/CS6503 Introduction to Relational Databases Dr Kieran T. Herley Summary Review of relation model. Simple SELECT-FROM and SIMPLE-FROM-WHERE queries. SQL s operators.

More information

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D

Interactive use. $ python. >>> print 'Hello, world!' Hello, world! >>> 3 $ Ctrl-D 1/60 Interactive use $ python Python 2.7.5 (default, Mar 9 2014, 22:15:05) [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin Type "help", "copyright", "credits" or "license" for more information.

More information

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

Introduction to: Computers & Programming: Review prior to 1 st Midterm 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

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review

More information

Programming to Python

Programming to Python Programming to Python Sept., 5 th Slides by M. Stepp, M. Goldstein, M. DiRamio, and S. Shah Compiling and interpreting Many languages require you to compile (translate) your program into a form that the

More information

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 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:

More information

Variables, Expressions, and Statements

Variables, Expressions, and Statements Variables, Expressions, and Statements Chapter 2 Python for Informatics: Exploring Information www.pythonlearn.com Constants Fixed values such as numbers, letters, and strings are called constants because

More information

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p.

27-Sep CSCI 2132 Software Development Lecture 10: Formatted Input and Output. Faculty of Computer Science, Dalhousie University. Lecture 10 p. Lecture 10 p.1 Faculty of Computer Science, Dalhousie University CSCI 2132 Software Development Lecture 10: Formatted Input and Output 27-Sep-2017 Location: Goldberg CS 127 Time: 14:35 15:25 Instructor:

More information

Logical Thinking through Computer Programming

Logical Thinking through Computer Programming Logical Thinking through Computer Programming Course Objectives To empower students. September 2, 2016 - September 23, 2016 Men s Honor Farm To elevate the technical literacy of the students. To help students

More information

CS313D: ADVANCED PROGRAMMING LANGUAGE

CS313D: ADVANCED PROGRAMMING LANGUAGE CS313D: ADVANCED PROGRAMMING LANGUAGE Computer Science department Lecture 2 : C# Language Basics Lecture Contents 2 The C# language First program Variables and constants Input/output Expressions and casting

More information

LISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University

LISTS WITH PYTHON. José M. Garrido Department of Computer Science. May College of Computing and Software Engineering Kennesaw State University LISTS WITH PYTHON José M. Garrido Department of Computer Science May 2015 College of Computing and Software Engineering Kennesaw State University c 2015, J. M. Garrido Lists with Python 2 Lists with Python

More information

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361)

Crayon (.cry) Language Reference Manual. Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361) Crayon (.cry) Language Reference Manual Naman Agrawal (na2603) Vaidehi Dalmia (vd2302) Ganesh Ravichandran (gr2483) David Smart (ds3361) 1 Lexical Elements 1.1 Identifiers Identifiers are strings used

More information

6.S189 Homework 1. What to turn in. Exercise 1.1 Installing Python. Exercise 1.2 Hello, world!

6.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 information

Chapter 2 C++ Fundamentals

Chapter 2 C++ Fundamentals Chapter 2 C++ Fundamentals 3rd Edition Computing Fundamentals with C++ Rick Mercer Franklin, Beedle & Associates Goals Reuse existing code in your programs with #include Obtain input data from the user

More information

Variable and Data Type I

Variable and Data Type I The Islamic University of Gaza Faculty of Engineering Dept. of Computer Engineering Intro. To Computers (LNGG 1003) Lab 2 Variable and Data Type I Eng. Ibraheem Lubbad February 18, 2017 Variable is reserved

More information

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017

CS Introduction to Computational and Data Science. Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 CS 133 - Introduction to Computational and Data Science Instructor: Renzhi Cao Computer Science Department Pacific Lutheran University Spring 2017 Previous class We have learned the path and file system.

More information

Scheme: Strings Scheme: I/O

Scheme: Strings Scheme: I/O Scheme: Strings Scheme: I/O CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Wednesday, April 5, 2017 Glenn G. Chappell Department of Computer Science University of

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types

More information

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

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?

More information

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 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;

More information

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

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

More information

Strings. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington

Strings. CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Strings CSE 1310 Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1 Strings Store Text In the same way that int and float are designed to store numerical values,

More information

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

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

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 07: Data Input and Output Readings: Chapter 4 Input /Output Operations A program needs

More information

Python Day 3 11/28/16

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:

More information

Lecture 7: Functions. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork

Lecture 7: Functions. CS1068+ Introductory Programming in Python. Dr Kieran T. Herley 2018/19. Department of Computer Science University College Cork Lecture 7: Functions CS1068+ Introductory Programming in Python Dr Kieran T. Herley 2018/19 Department of Computer Science University College Cork Summary Functions in Python. Terminology and execution.

More information

Visual C# Instructor s Manual Table of Contents

Visual C# Instructor s Manual Table of Contents 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

More information

Lecture 11: while loops CS1068+ Introductory Programming in Python. for loop revisited. while loop. Summary. Dr Kieran T. Herley

Lecture 11: while loops CS1068+ Introductory Programming in Python. for loop revisited. while loop. Summary. Dr Kieran T. Herley Lecture 11: while loops CS1068+ Introductory Programming in Python Dr Kieran T. Herley Python s while loop. Summary Department of Computer Science University College Cork 2017-2018 KH (24/10/17) Lecture

More information

Objectives. In this chapter, you will:

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

More information

A variable is a name for a location in memory A variable must be declared

A variable is a name for a location in memory A variable must be declared Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

More information

The current topic: Python. Announcements. Python. Python

The current topic: Python. Announcements. Python. Python The current topic: Python Announcements! Introduction! reasons for studying languages! language classifications! simple syntax specification Object-oriented programming: Python Types and values Syntax

More information

Lexical Analysis and jflex

Lexical Analysis and jflex Lecture 6: Lexical Analysis and jflex Dr Kieran T. Herley Department of Computer Science University College Cork 2017-2018 KH (03/10/17) Lecture 6: Lexical Analysis and jflex 2017-2018 1 / 1 Summary Lexical

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

My First Python Program

My First Python Program My First Python Program Last Updated: Tuesday, January 22, 2019 Page 2 Objective, Overview Introduction Now that we have learned about the Python Shell, you will now put it all together and write a python

More information

Getting started with Java

Getting started with Java Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ 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

More information

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

More information

Lecture 1. basic Python programs, defining functions

Lecture 1. basic Python programs, defining functions Lecture 1 basic Python programs, defining functions Lecture notes modified from CS Washington CS 142 Except where otherwise noted, this work is licensed under: http://creativecommons.org/licenses/by-nc-sa/3.0

More information

COMP1730/COMP6730 Programming for Scientists. Strings

COMP1730/COMP6730 Programming for Scientists. Strings COMP1730/COMP6730 Programming for Scientists Strings Lecture outline * Sequence Data Types * Character encoding & strings * Indexing & slicing * Iteration over sequences Sequences * A sequence contains

More information

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) First Name: Last Name: NetID:

CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28)   First Name: Last Name: NetID: CS 1110 SPRING 2016: GETTING STARTED (Jan 27-28) http://www.cs.cornell.edu/courses/cs1110/2016sp/labs/lab01/lab01.pdf First Name: Last Name: NetID: Goals. Learning a computer language is a lot like learning

More information

Impera've Programming

Impera've Programming Impera've Programming Python Programs Interac)ve Input/Output One- Way and Two- Way if Statements for Loops User- Defined Func)ons Assignments Revisited and Parameter Passing Python program line1 = 'Hello

More information

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

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d. Gaddis: Starting Out with Python, 2e - Test Bank Chapter Two MULTIPLE CHOICE 1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical

More information

CS1110 Lab 1 (Jan 27-28, 2015)

CS1110 Lab 1 (Jan 27-28, 2015) CS1110 Lab 1 (Jan 27-28, 2015) First Name: Last Name: NetID: Completing this lab assignment is very important and you must have a CS 1110 course consultant tell CMS that you did the work. (Correctness

More information