Text Copyright (c) 2017 by Dr. E. Horvath

Slides:



Advertisements
Similar presentations
Types and Arithmetic Operators
Advertisements

©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
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”?
Basic C Programming Data Types and Arithmetic Operations 01/30/15.
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
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”?
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to Python Programming Outline 2.1 Introduction 2.2 First Program in Python: Printing.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
Basic Input/Output and Variables Ethan Cerami New York
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter 2: Variables, Operations, and Strings CSCI-UA 0002 – Introduction to Computer Programming Mr. Joel Kemp.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Introduction to Computational Linguistics Programming I.
PYTHON. Python is a high-level, interpreted, interactive and object- oriented scripting language. Python was designed to be highly readable which uses.
Sep 12, 2007Sprenkle - CS1111 Objectives Review  Linux  Why programming languages? Compiled vs. Interpreted Languages Programming in Python  Data types.
Input, Output, and Processing
Computer Science 101 Introduction to Programming.
Chapter 2: Using Data.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Variables, Expressions and Statements
ECS 15 Variables. Outline  Using IDLE  Building blocks of programs: Text Numbers Variables!  Writing a program  Running the program.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
Data Types Declarations Expressions Data storage C++ Basics.
Chapter 2 Variables.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Numbers1 Working with Numbers There are times that we have to work with numerical values. When we count things, we need Integers or whole numbers. When.
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,
 Variables can store data of different types, and different data types can do different things.  PHP supports the following data types:  String  Integer.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Literals A literal (sometimes called a constant) is a symbol which evaluates to itself, i.e., it is what it appears to be. Examples: 5 int literal
Input, Output and Variables GCSE Computer Science – Python.
28 Formatted Output.
Numbers and arithmetic
Fundamentals of Programming I Overview of Programming
Chapter 2 Variables.
Numbers and Arithmetic
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Data Types and Conversions, Input from the Keyboard
2.5 Another Java Application: Adding Integers
Introduction to Programming
Variables, Expressions, and IO
Introduction to Scripting
Introduction to Programming
Introduction to Programming
And now for something completely different . . .
Introduction to C++ Programming
Chapter 2 Variables.
Reading Input from the Keyboard
Topics Designing a Program Input, Processing, and Output
Introduction to Programming
Topics Designing a Program Input, Processing, and Output
Introduction to Java Applications
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
EECE.2160 ECE Application Programming
Introduction to Programming
Unit 3: Variables in Java
Chapter 2 Variables.
EECE.2160 ECE Application Programming
Presentation transcript:

Text Copyright (c) 2017 by Dr. E. Horvath Creating Python 3 Scripts, Declaring Variables, Arithmetic Operators, and Formatting Text Copyright (c) 2017 by Dr. E. Horvath

Creating Python 3 Scripts Menu → Programming → Python 3 (IDLE) IDLE = Integrated Developers Environment File → New File Run → Run Module or press F5 to run Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath Declaring Variables An assignment statement is sufficient to declare a variable. The type of the data is based on the values assigned to a variable. count = 5 temperature = 98.6 name = “Your name” print(“count “ + str(count)) print outputs a value in the shell Text Copyright (c) 2017 by Dr. E. Horvath

Precedence ( ) Parentheses ** Exponentiation +x, -x Positive, Negative * / % Multiplication, Division, Remainder + - Addition, Subtraction <, <=, >, >=, !=, == Relational Operators not x Boolean NOT and Boolean AND or Boolean OR

Text Copyright (c) 2017 by Dr. E. Horvath Input data count = input(“Enter the count”) Prompt the user for input count = int(count) Convert to an integer print(“count “ + str(count)) print outputs a value in the shell + concatenate strings str(count) covert to a string for output temperature= input(“Enter the temperature”) temperature = float(temperature) Convert to a floating point value name = input(“Enter your name”) print(“name = “ + name) Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath Escape Characters print(“\”Your name \”\n”) \” Print a double quote \n New line character Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath round function The round function rounds a floating point value to a specific number of decimal places. h = 45.442564 h1 = round(h,2) h1 = 45.44 h2 = round(h,1) h2 = 45.4 Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath Formatting Output pi = 3.14159 name = “Your name” msg = "pi: "+ format(pi,'7.2f') 7 spaces, 2 decimal places of precision f indicates floating point msg = "pi: "+ format(pi,'0.3e') no additional spaces before the decimal point 3 decimal places of precision e indicates exponential Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath Formatting Output pi = 3.14159 name = “Your name” msg = "pi: "+ format(p,'10,.2f') 10 spaces, comma for thousand places, 2 decimal places of precisions f indicates floating point msg = "name: "+ format(name,'15s'') 15 spaces s indicates string data Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath Formatting Output pi = 3.14159 hours = 24 msg = “pi {:7.2f} hours {:3d}".format(pi,hours) 7 spaces, 2 decimal places of precision f indicates floating point 3 spaces for an integer data Text Copyright (c) 2017 by Dr. E. Horvath

Text Copyright (c) 2017 by Dr. E. Horvath Formatting Output msg = "pi {0:7.2e} hours {1:04d}".format(pi,hours) 7 spaces before the decimal point 2 decimal places of precision e indicates exponential preceeding zero, 4 spaces for an integer name = “Your name” msg = Your name is {0:>15s}".format(name) 15 spaces > indicates right align s indicates string Text Copyright (c) 2017 by Dr. E. Horvath