Introduction to Programming Using Python PART 2

Slides:



Advertisements
Similar presentations
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Advertisements

Conditional statements and Boolean expressions. The if-statement in Java (1) The if-statement is a conditional statement The statement is executed only.
Conditional Statements Introduction to Computing Science and Programming I.
Chapter 4 Control Structures I. Objectives ► Examine relational and logical operators ► Explore how to form and evaluate logical (Boolean) expressions.
Slide 1 Summary Two basic concepts: variables and assignments Some C++ practical issues: division rule, operator precedence  Sequential structure of a.
Structured programming
Program Design and Development
General Computer Science for Engineers CISC 106 Lecture 10 Roger Craig Computer and Information Sciences 3/06/2009.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
INTRODUCTION TO PYTHON PART 3 - LOOPS AND CONDITIONAL LOGIC CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
Chapter 9 IF Statement Bernard Chen. If Statement The main statement used for selecting from alternative actions based on test results It’s the primary.
4. Python - Basic Operators
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
CH Programming An introduction to programming concepts.
Python Lab: Control Statements Conditionals, Loops, Iterations Proteomics Informatics, Spring 2014 Week 4 18 th Feb, 2014
Python – Making Decisions Lecture 02. Control Structures A program that only has one flow is useful but limited. We can use if statements to make these.
Bell Ringer = – 5 = = ÷ -2 = =6. -7 – (-7) = After you have completed the bell ringer, take out your homework!
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Code Grammar. Syntax A set of rules that defines the combination of symbols and expressions.
Basic Control Structures
Lesson - 5. Introduction While programming, we usually need to decide the path of the program flow according to the parameters and conditions. Actually.
© ABB University - 1 Revision C E x t e n d e d A u t o m a t i o n S y s t e m x A Chapter 11 Structured Text Course T314.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
9/14/2015BCHB Edwards Introduction to Python BCHB Lecture 4.
Assignment statement: Assigns a value to a variable Variable must appear on the left side, value on the right side of the assignment operator Right side.
Program Development C# Programming January 30, 2007 Professor J. Sciame.
Python Mini-Course University of Oklahoma Department of Psychology Day 3 – Lesson 10 Iteration: Loops 05/02/09 Python Mini-Course: Day 3 - Lesson 10 1.
1 CS 177 Week 6 Recitation Slides Review for Midterm Exam.
September 7, 2004ICP: Chapter 3: Control Structures1 Introduction to Computer Programming Chapter 3: Control Structures Michael Scherger Department of.
Operators.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
PYTHON VARIABLES : CHAPTER 2 FROM THINK PYTHON HOW TO THINK LIKE A COMPUTER SCIENTIST.
AOIT Introduction to Programming Unit 2, Lesson 6 Arithmetic Operators and Operator Precedence Copyright © 2009–2012 National Academy Foundation. All rights.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Chad’s C++ Tutorial Demo Outline. 1. What is C++? C++ is an object-oriented programming (OOP) language that is viewed by many as the best language for.
Control Flow (Python) Dr. José M. Reyes Álamo. 2 Control Flow Sequential statements Decision statements Repetition statements (loops)
PH2150 Scientific Computing Skills Control Structures in Python In general, statements are executed sequentially, top to bottom. There are many instances.
 Type Called bool  Bool has only two possible values: True and False.
Math operations 9/19/16.
Introduction to Python
G. Pullaiah College of Engineering and Technology
Control Flow (Python) Dr. José M. Reyes Álamo.
Introduction to Python
Sequence, Selection, Iteration The IF Statement
Introduction to Programming
Introduction to MATLAB
Logical Operators, Boolean Data Types
Selection CIS 40 – Introduction to Programming in Python
Arithmetic operations, decisions and looping
Introduction to Variables, Algebraic Expressions, and Equations
Chapter 3 – Control Structures
CSC215 Lecture Flow Control.
CSC215 Lecture Control Flow.
3. Decision Structures Rocky K. C. Chang 19 September 2018
Introduction to Python
Summary Two basic concepts: variables and assignments Basic types:
Computer Science Core Concepts
Chapter 3: Selection Structures: Making Decisions
Introduction to Python
CHAPTER 5: Control Flow Tools (if statement)
Matlab Basics.
CSC215 Lecture Control Flow.
Class code for pythonroom.com cchsp2cs
REPETITION Why Repetition?
LOOP Basics.
COMPUTING.
Types, Truth, and Expressions (Part 2)
Presentation transcript:

Introduction to Programming Using Python PART 2 MIS 201 Management Information Systems Lab Session 2

Outline Why programming? Python basics: comments, numbers, strings, and variables Operations and expression: logical operators, order of execution, and expressions Control flow: conditional execution using “if” statements

Operators and Expressions Arithmetic operators: Plus (+): addition 3+3=6 Minus (-): subtraction 10.2-3.1=7.1 Multiply (*): multiplication 9*10=90 Power (**): x**y gives x to the power y 2**3=8 Divide (/): division 5/2=2.5 Divide and floor (//): returns the result rounded to nearest integer 5//2=2 Module (%): returns the reminder after the division as integer 14%5=4

Operators and Expressions Logical operators: AND (&) True & True  True OR (|) True | False  True Less than (<) 9 < 10  True Less then or equal to (<=) 12 <= 12  True Greater than (>) 90 > 100  False Greater than or equal to (>=) 12 >= 9  True Equal (==) 12 == 12  True Not equal (!=) 29 != 19  True

Evaluation Order What is the result of the following expression? 2+5*6**2/9-10 = ? PEMDAS rule (parentheses, exponential, multiplication, division, addition, subtraction) Use of parentheses to enforce specific order ((2+5)*6**2)/9-10 = ? ((2+5)*6**2)/(9-10) = ?

Expressions Expressions are representation of variables with operators, and the compiler (the computer) evaluates the expression whenever the code is executed. Evaluate and store Evaluate only

Control Flow Statements executed by Python in exact top-down order (every line is executed once in top-down order) In order to control the flow of execution logic, we use control flow operators: Conditional execution A line (or set of lines) executed only if a condition is satisfied (if statement) Repetition of execution Conditional loop: while loop Sequential loop: for loop

The if statement Simple if statement (single condition) if condition: ## Code executed if condition is met If-else statement (single condition) else: ## Code executed if condition is NOT met If-elif-else statement (multiple conditions) if condition1: ## Code executed if condition1 is met elif condition2: ## Code executed if condition2 is met ## Code executed if both conditions are NOT met

The if statement - Examples Simple if statement if temperature>=30: print(“Today is hot”) If-else statement else: print(“Today is cold”) If-elif-else statement elif temperature<30 & temperature>=18: print(“Today is nice”)

The while Statement A line (or set of lines; code block) is repeatedly executed only if a condition is satisfied while condition: ## Code executed as long as condition is met ## Code to change condition value The condition to evaluate must contain a changing variable; otherwise, the code block will never stop! Example x=10 while x<100: print("x is less than 100. x=", x) x=x*2 print("while loop stopped because x is > than 100. x=",x)

The for Loop A line (or set of lines; code block) is sequentially executed for a specific range if variable in (range): ## Code is executed number of times as defined… ## in the range of the for…in loop The range has a beginning and end numbers Example ## Printing first 10 multipliers of 3 for m in range(1,11): print(m*3)

End of Python Introduction