INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter.

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
Intro to Robots Robots are Everywhere. Intro to Robots Various robots in use today lawnmower pet baby seal for convalescents gutter cleaner home security.
Python November 14, Unit 7. Python Hello world, in class.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Python Programming Chapter 2: Variables, expressions, and statements Saad Bani Mohammad Department of Computer Science Al al-Bayt University 1 st 2011/2012.
Introduction to Python
Chapter 2 Writing Simple Programs
CS 1 with Robots Variables, Data Types & Math Institute for Personal Robots in Education (IPRE)‏
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Basic Input/Output and Variables Ethan Cerami New York
Variables, Expressions, and Statements
COMPUTER SCIENCE I C++ INTRODUCTION
Python.
Lecture 2 - Variables, program execution, calculations, print() COMPSCI 101 Principles of Programming.
Introduction to Python
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
CPTR 124 Review for Test 1. Development Tools Editor Similar to a word processor Allows programmer to compose/save/edit source code Compiler/interpreter.
Programming in Python Part I Dr. Fatma Cemile Serçe Atılım University
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 2 Input,
PhD, Senior Lecturer, Baimuratov Olimzhon A LGORITHMS & P ROGRAMMING (P YTHON ) Lecture 2 From SDU:
Input, Output, and Processing
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
INLS 560 – C ONDITIONALS Instructor: Jason Carter.
Variables and Expressions CMSC 201 Chang (rev )
Week 1 Algorithmization and Programming Languages.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
COMP 171: Data Types John Barr. Review - What is Computer Science? Problem Solving  Recognizing Patterns  If you can find a pattern in the way you solve.
Variables, Expressions, and Statements
1 Week 1: Variables, assignment, expressions READING: 1.2 – 1.4.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Variables, Expressions and Statements
1 COMS 261 Computer Science I Title: C++ Fundamentals Date: September 9, 2005 Lecture Number: 6.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
INLS 560 – F UNCTIONS Instructor: Jason Carter.
Variables and Expressions CMSC 201. Today we start Python! Two ways to use python: You can write a program, as a series of instructions in a file, and.
Python Let’s get started!.
Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
Data Manipulation Variables, Data Types & Math. Aug Variables A variable is a name (identifier) that points to a value. They are useful to store.
I NTRODUCTION TO PYTHON - GETTING STARTED ( CONT )
Chapter 2 Writing Simple Programs
Topics Designing a Program Input, Processing, and Output
Input and Output Upsorn Praphamontripong CS 1110
Python Let’s get started!.
BASIC ELEMENTS OF A COMPUTER PROGRAM
Revision Lecture
Presented By S.Yamuna AP/IT
Variables, Expressions, and IO
Variables, Expressions, and Statements
Reading Input from the Keyboard
Variables, Expressions, and Statements
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
CS150 Introduction to Computer Science 1
Variables, Expressions, and Statements
15-110: Principles of Computing
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Presentation transcript:

INLS 560 – V ARIABLES, E XPRESSIONS, AND S TATEMENTS Instructor: Jason Carter

W HAT IS A P ROGRAM ? Set of instructions that a computer follows to perform a task or solve a problem

I NSTRUCTIONS 29 keywords and. def, exec, if, not, return assert, del, finally, import, or, try break, elif, for, in, pass, while class, else, from, is, print, yield continue, except, global, lambda, raise

H ELLO W ORLD E XAMPLE print “Hello, World!” Keyword Value Output: Hello World

A NOTHER E XAMPLE print Keyword Value Output: 2

V ALUES H AVE T YPES print “Hello, World!” The value “Hello World” is a type of string A string is a sequence of characters A string can be identified because it is enclosed in quotes. Keyword

A NOTHER T YPE E XAMPLE print The value 2 is a type of integer A non-decimal numerical value There are many different types Keyword

V ARIABLES A variable is a name that refers to a value A name that represents a value stored in the computer memory Assignment statement: used to create a variable and make it reference data General format is variable = expression Example: age = 29 Assignment operator: the equal sign (=)

A SSIGNMENT S TATEMENT In an assignment statement, variable receiving value must be on left side You can only use a variable if a value is assigned to it message = "What’s up, Doc?“ n = 17 pi =

V ARIABLE N AMES AND K EYWORDS Rules for naming variables in Python: Variable name cannot be a Python key word Variable name cannot contain spaces First character must be a letter or an underscore After first character may use letters, digits, or underscores Variable names are case sensitive Variable name should reflect its use Legal message = "What’s up, Doc?“ n = 17 pi = Illegal 76trombones = ’big parade’ more$ = class = ’Computer Science 101’

M ANIPULATING V ARIABLES Variables can be: Printed message = "What’s up, Doc?” print message Output: What’s up Doc Reassigned message = "What’s up, Doc?” message = “Hello?” print message Output: Hello? print and assignment are two kinds of statements

S TATEMENT A statement is an instruction that the Python interpreter can execute print 1 x = 2 print x Output: 1 2 The assignment statement does not produce output.

R EVIEW Python has 29 keywords Variable A variable is a name that refers to a value Assignment statement used to create a variable and make it reference data Statement an instruction that the Python interpreter can execute

E XPRESSIONS

O RDER OF O PERATIONS Follows same rule of precedence as mathematics PEMDAS Parentheses Exponentiation Multiplication and Division Addition and Subtraction Evaluate the expression: (4 + 4) - 3

I NPUT F ROM K EYBOARD Most programs need to read input from the user Built-in input function reads input from keyboard Returns the data as a string Format: variable = input(prompt) prompt is typically a string instructing user to enter a value Does not automatically display a space after the prompt Example: name = input(“Please enter your name: ”)

R EADING N UMBERS WITH THE INPUT F UNCTION input function always returns a string Built-in functions convert between data types int(item) converts item to an int float(item) converts item to a float Type conversion only works if item is valid numeric value, otherwise, throws exception

I NPUT F ROM K EYBOARD For integers: variable = int(input("Prompt")) For floats: variable = float(input("Prompt")) For strings: variable = input("Prompt")

P RACTICE Write a program that takes Two numbers from a user Print out the sum, difference, product, and quotient of the two numbers