Numbers. Number data types store numeric values They are immutable data types, which means that changing the value of a number data type results in a.

Slides:



Advertisements
Similar presentations
Building Java Programs
Advertisements

Return values.
Maths & Trig, Statistical functions. ABS Returns the absolute value of a number The absolute value of a number is the number without its sign Syntax ◦
Chapter 3: Expressions and Interactivity. Outline cin object Mathematical expressions Type Conversion and Some coding styles.
A Library of Functions This presentation will review the behavior of the most common functions including their graphs and their domains and ranges. See.
Data types, declarations, and expressions in Java.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Copyright © 2012 Pearson Education, Inc. Chapter 3: Expressions and Interactivity.
1 Fundamental Data Types. 2 Outline  Primitive Data Types  Variable declaration  Numbers and Constants  Arithmetic Operators  Arithmetic Operator.
BIL101, Introduction to Computers and Information Systems Chapter 12 A Portable Scientific Visualization Program: GnuPlot Prepared by Metin Demiralp Istanbul.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 3: Expressions and Interactivity.
Topic 2A – Library Functions and Casting. CISC 105 – Topic 2A Functions A function is a piece of code which performs a specific task. When a function.
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
Integer Exponents and Scientific Notation
Mrs.Volynskaya Real Numbers
What is a variable?  A variable holds data in memory so the program may use that data, or store results.  Variables have a data type. int, boolean, char,
WHAT KIND OF THING IS IT? Python: Basic Numeric Types
Python Crash Course strings, math 3 rd year Bachelors V1.0 dd Hour 7.
8. Python - Numbers Number data types store numeric values. They are immutable data types, which means that changing the value of a number data type results.
Section 1.1 Numbers and Their Properties.
Chapter 1 Foundations for Algebra
Expressions and Interactivity Chapter 3. 2 The cin Object Standard input object Like cout, requires iostream file Used to read input from keyboard Often.
Vahé Karamian Python Programming CS-110 CHAPTER 3 Computing with Numbers.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved Streams Streams –Sequences of characters organized.
VOCABULARY. The set {0, 1, 2,….} Whole Numbers VOCABULARY Lines and sets that never end continue to… Infinity.
Chapter 9 Formatted Input/Output. Objectives In this chapter, you will learn: –To understand input and output streams. –To be able to use all print formatting.
ALGEBRA 1. Lesson 1-3 Warm-Up ALGEBRA 1 Lesson 1-3 Warm-Up.
FUNCTIONS. Function call: >>> type(32) The name of the function is type. The expression in parentheses is called the argument of the function. Built-in.
D ATA T YPE. NUMBERS A number is an immutable type – means that changing or updating its value result in a newly allocated object. There are several types.
IMS 3253: Math 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Five Fundamental Math Operations Precedence of Math.
Chapter 3.  Traditionally, programming languages have assigned different types of data for different types of numbers.  In many languages, there may.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
CSC1015F – Chapter 3, Computing with Numbers Michelle Kuttel
CSE1222: Lecture 4The Ohio State University1. Mathematical Functions (1)  The math library file cmath Yes, this is a file with definitions for common.
CSE202: Lecture 4The Ohio State University1 Mathematical Functions.
Input, Output, and Processing
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Week 2 - Friday.  What did we talk about last time?  Using Scanner to get input  Basic math operations.
STANDARD FUNCTIONS Computer Programming Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
CSC Programming for Science Lecture 7: Math Functions.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. int: integers, no fractional part: 1, -4, 0 double : floating-point.
Variables and Expressions, continued CMSC 201. Expressions Anything on the right hand side of an assignment is an expression. An expression is anything.
Python break,continue and pass Statements. The break Statement: for letter in 'Python': # First Example if letter == 'h': break print 'Current Letter.
Visual Basic I Programming
Chapter 6 Mathematical Operations. 6.1 Mathematical Expressions In mathematics this expression is valid 0 = -4y + 5 It is invalid in programming Left.
Expressions and Interactivity. 3.1 The cin Object.
B121 Chapter 5 Working with Numbers. Number representation ThousandHundredsTensUnits Natural numbers: 1,2,3,4,5……… Integers: Natural numbers.
3. COMPUTING WITH NUMBERS Rocky K. C. Chang September 10, 2015 (Adapted from John Zelle’s slides)
22 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
29 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Hazırlayan:Emin BORANDAĞ 2/17/ Numerik Değerler Kullanımı Integers are considered accurate up to 15 digits. Try it function myFunction() { var x.
Header File cmath(math.h) C++. cmath Header File cmath / math functions Function name and parameters Parameters typeFunction return value acos(x)x is.
Useful Python CMSC 120: Visualizing Information. Scope def area(diameter): radius = diameter / 2.0 A = PI * radius ** 2 return A def circumference(diameter):
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Variables, Operators, and Expressions
Simple C Programs.
Numeric Functions Purpose:-
Python Variable Types.
ECE 1304 Introduction to Electrical and Computer Engineering
BIL 104E Introduction to Scientific and Engineering Computing
Introduction to Programming
Arithmetic operations, decisions and looping
Numerical Data Types.
Numbers.
Lecture 9: Arrays Building Java Programs: A Back to Basics Approach
Introduction to Programming with Python
Class code for pythonroom.com cchsp2cs
Presentation transcript:

Numbers

Number data types store numeric values They are immutable data types, which means that changing the value of a number data type results in a newly allocated object. Number objects are created when you assign a value to them. For example: var1 = 1 var2 = 10 You can also delete the reference to a number object by using the del statement. The syntax of the del statement is: del var1[,var2[,var3[....,varN]]]] You can delete a single object or multiple objects by using the del statement. For example: del var del var_a, var_b

four different numerical types int (signed integers): often called just integers or ints, are positive or negative whole numbers with no decimal point. long (long integers ): or longs, are integers of unlimited size, written like integers and followed by an uppercase or lowercase L. float (floating point real values): or floats, represent real numbers and are written with a decimal point dividing the integer and fractional parts. Floats may also be in scientific notation, with E or e indicating the power of 10 (2.5e2 = 2.5 x 10 2 = 250). complex (complex numbers) : are of the form a + bJ, where a and b are floats and J (or j) represents the square root of -1 (which is an imaginary number). a is the real part of the number, and b is the imaginary part. Complex numbers are not used much in Python programming.

Examples intlongfloatcomplex L j 100-0x19323L j L e-36j 0800xDEFABCECBDAECB FBAEL 32.3+e18.876j L J -0x L-32.54e1003e+26J 0x L70.2-E124.53e-7j

note Python allows you to use a lowercase l with long, but it is recommended that you use only an uppercase L to avoid confusion with the number 1. Python displays long integers with an uppercase L. A complex number consists of an ordered pair of real floating point numbers denoted by a + bj, where a is the real part and b is the imaginary part of the complex number.

Number Type Conversion Type int(x) to convert x to a plain integer. Type long(x) to convert x to a long integer. Type float(x) to convert x to a floating-point number. Type complex(x) to convert x to a complex number with real part x and imaginary part zero. Type complex(x, y) to convert x and y to a complex number with real part x and imaginary part y. x and y are numeric expressions

conversion x = print int(x) print long(x) print float(x) print complex(x) OUTPUT ( j)

4 types x = 99 y = x print type(y) y = int(x) print type(y) y = long(x) print type(y) y = float(x) print type(y) y = complex(x) print type(y) output

More “casting” x = y = x print type(y) y = int(x) print type(y) y = long(x) print type(y) y = float(x) print type(y) y = complex(x) print type(y) output

Mathematical Functions 1 FunctionReturns ( description ) abs(x)The absolute value of x: the (positive) distance between x and zero. ceil(x)The ceiling of x: the smallest integer not less than x cmp(x, y)-1 if x y exp(x)The exponential of x: e x fabs(x)The absolute value of x. floor(x)The floor of x: the largest integer not greater than x log(x)The natural logarithm of x, for x> 0

Mathematical Functions 2 FunctionReturns ( description ) log10(x)The base-10 logarithm of x for x> 0. max(x1, x2,...)The largest of its arguments: the value closest to positive infinity min(x1, x2,...)The smallest of its arguments: the value closest to negative infinity modf(x)The fractional and integer parts of x in a two-item tuple. Both parts have the same sign as x. The integer part is returned as a float. pow(x, y)The value of x**y. round(x [,n])x rounded to n digits from the decimal point. Python rounds away from zero as a tie-breaker: round(0.5) is 1.0 and round(-0.5) is sqrt(x)The square root of x for x > 0

Random Number Functions FunctionDescription choice(seq)A random item from a list, tuple, or string. randrange ([start,] stop [,step]) A randomly selected element from range(start, stop, step) random()A random float r, such that 0 is less than or equal to r and r is less than 1 seed([x])Sets the integer starting value used in generating random numbers. Call this function before calling any other random module function. Returns None. shuffle(lst)Randomizes the items of a list in place. Returns None. uniform(x, y)A random float r, such that x is less than or equal to r and r is less than y

Trigonometric Functions FunctionDescription acos(x)Return the arc cosine of x, in radians. asin(x)Return the arc sine of x, in radians. atan(x)Return the arc tangent of x, in radians. atan2(y, x)Return atan(y / x), in radians. cos(x)Return the cosine of x radians. hypot(x, y)Return the Euclidean norm, sqrt(x*x + y*y). sin(x)Return the sine of x radians. tan(x)Return the tangent of x radians. degrees(x)Converts angle x from radians to degrees. radians(x)Converts angle x from degrees to radians.

Mathematical Constants ConstantsDescription piThe mathematical constant pi. eThe mathematical constant e.