Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012

Slides:



Advertisements
Similar presentations
Chapter 19, 20 Object Oriented Programming (OOP) Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Advertisements

Huffman Encoding Dr. Bernard Chen Ph.D. University of Central Arkansas.
Objectives Learn about objects and reference variables Explore how to use predefined methods in a program.
Python November 18, Unit 7. So Far We can get user input We can create variables We can convert values from one type to another using functions We can.
Business Statistics BU305 Chapter 3 Descriptive Stats: Numerical Methods.
Chapter2 Digital Components Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
An Introduction to C Programming Geb Thomas. Learning Objectives Learn how to write and compile a C program Learn what C libraries are Understand the.
Homework 4 Example Bernard Chen How do we generate Random number in Python Random is a very important method in math and statistics, how could we.
Boolean Algebra Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
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.
Chapter 9 IF Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Ch 1. Introduction Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
MCS 177 Lab Fall 2014 Sept. 2, GUSTAVUS ADOLPHUS COLLEGEgustavus.edu Contact Info Course Instructor: Louis Yu Lab.
Hands on Projects Dr. Bernard Chen Ph.D. University of Central Arkansas July 9 th 2012
Computing with Numbers CSC 161: The Art of Programming Prof. Henry Kautz 9/14/2009.
Introduction to Python
Python 101 Dr. Bernard Chen University of Central Arkansas IT Academic.
Introduction to Python 2 Dr. Bernard Chen University of Central Arkansas PyArkansas 2011.
Chapter 4 Numbers. Python Program Structure Python programs consist of: Modules Statements Expressions Objects.
Computing with Numbers Zelle - Chapter 3 Charles Severance - Textbook: Python Programming: An Introduction to Computer Science, John.
Chapter 3.  Traditionally, programming languages have assigned different types of data for different types of numbers.  In many languages, there may.
Python Types Python values are of various “types” Ints, Floats, Strings, Characters, and more Two representations of numbers 1 vs 1.0.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley STARTING OUT WITH Python Python First Edition by Tony Gaddis Chapter 6 Value-Returning.
Now String theory To Do: Lists This stuff hurts my brane. when you learn string theory from google images… Goal: Thinking like a machine You should now.
OCR Computing GCSE © Hodder Education 2013 Slide 1 OCR GCSE Computing Python programming 6: Variables and constants.
1 CSE1301 Computer Programming Lecture 5: Components of a C Program (Part 1) Linda M c Iver.
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
Operators in Python. Arithmetic operators Some operators in Python will look familiar (+, -, *, /) Others are new to you (%, //, **) All of these do work.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions Image taken from:
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Introduction to C Programming Chapter 2 : Data Input, Processing and Output.
Numbers © Copyright 2014, Fred McClurg All Rights Reserved.
Variables When programming it is often necessary to store a value for use later on in the program. A variable is a label given to a location in memory.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
APS105 Calculating 1. Basic Math Operations 2 Basic Arithmetic Operators Operators: –Addition: + –Subtraction: - –Multiplication: * –Division: / Recall.
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.
Python 101 Dr. Bernard Chen University of Central Arkansas PyArkansas.
3. COMPUTING WITH NUMBERS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
COP 2510 Chapter 6 - Functions. Random function (randint) #import the desired function import random #integer random number in the range of 1 through.
Chapter 1 Introduction to PHP Part 1. Textbook’s Code DOWNLOADS PHP and MySQL for Dynamic Web Sites Complete Set of Scripts.
A: A: double “4” A: “34” 4.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
Chapter 15. Modules Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
XYZCS Designing Binary Adders with decoders C(X,Y,Z) =  m(3,5,6,7) S(X,Y,Z) = S m(1,2,4,7);
Chapter 4 Numbers CSC1310 Fall Python Program Structure import math r=int(raw_input()) print 4.0/3*math.pi*r**3 volume.py: Program Program Module.
1 Section 3.2b Arithmetic Operators Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Thinking about programming
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Week of 12/12/16 Test Review.
Data Types and Conversions, Input from the Keyboard
Dr. Bernard Chen Ph.D. University of Central Arkansas
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Combinational Circuits
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Introduction to Python
Numerical Functions & Tricks
Functions, Part 2 of 3 Topics Functions That Return a Value
Reference Parameters.
Variables and Expressions
Introduction to Value-Returning Functions: Generating Random Numbers
CHAPTER 3: String And Numeric Data In Python
Arithmetic Operations
Data Types and Maths Programming Guides.
Chapter3 Fixed Point Representation
Functions, Part 2 of 3 Topics Functions That Return a Value
More Basics of Python Common types of data we will work with
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012 Chapter 4 Numbers Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012

Python Build-in types Numbers 3.1415 Strings “Hello World” Lists [1,2,3,4] Files input=open(‘file.txt’, ‘r’)

Numbers Many different types, we only provide 3 here for now: Integer Floating-point Long integer

Number in Action Perhaps the best way to understand numerical objects is to see them in action. >>> a=3 #Name Created >>> b=4

Number in Action >>> a+1 # (3+1) 4 >>> a-1 #(3-1) 2

Number in Action >>> b*3 12 >>>b/2 2

Number in Action >>> b**2 #power 16 >>> a%2 #remainder 1

Number in Action >>> 2+4.0, #mix type 6.0 >>> 2.0**b 16.0

Number in Action >>> b / 2 + a >>> b/(2.0+a)

Number in Action >>> 1 / 2.0 0.5 >>> 1/2

Long Integers >>> 2L ** 200 >>> 2 ** 200

Class Practice >>> num= 1/3.0 >>> num >>> b=20 >>> c=a+b >>> c

Other Numeric Tools >>>int(2.567) 2 >>> round(2.567) 3.0 >>> round(2.567, 2) 2.57

Other Numeric Tools Math library >>> import math >>> math.pi 3.141592653589793 >>> math.e 2.718281828459045 http://docs.python.org/library/math.html

Other Numeric Tools Random Library >>> import random >>> random.randint(1,100) 25 45 17 http://docs.python.org/library/random.html

Dynamic Typing >>> a = 3 Create an object to represent the value of 3 Create the variable a, if it does not yet exist Link the variable a to the new object 3

a = 3

Share Reference >>> a=3 >>> b=a

Share Reference >>>a=3 >>>b=a >>>a=5

Dynamic Typing >>>a=3 >>>b=a >>>a=5.0

Class Practice >>> int(3.1415926) >>> round(3.1415926) >>> round(3.1415926, 3) >>> import math >>> round(math.pi, 3)

Class Practice >>> a=10 >>> b=20 >>> a+b >>> a=a+10 >>> a >>> b=b+10.0+a >>> b