PythonNumbersAnd1DArraysofNumbers

PythonNumbersAnd1DArraysofNumbers - approximate, the...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Python Numbers and 1-D Arrays of Numbers 1 © Popescu 2012
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Numbers Reading assignment: Chapter 3 from Zelle Numbers w/o fractional part: integers, or int for short Numbers w/ fractional part: floating-point numbers, or floats for short 2
Background image of page 2
Int or float Type does not have to be declared explicitly Python infers type based on presence or absence of decimal point operands Special Python function type returns the type float or int >>> type(2) <class 'int'> >>> type(2.0) <class 'float'> >>> type(1+2) <class 'int'> >>> type(1 + 2.0) <class 'float'> 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Built-in numeric operations 4
Background image of page 4
Built-in numeric operations 5
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
iClicker Question Explain the result in the Python shell window A. The result should be 1.15, you have discovered a Python bug B. The Python shell window image was photoshop-ed to show the incorrect result C. 3.45 cannot be represented precisely in base 2, so, since one operand is
Background image of page 6
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 10
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 12
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 14
Background image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: approximate, the division result is approximate D. 3.45 divided by 3.0 is a little more than 1.15, theres nothing to explain E. We should have used integer division // for the correct result 6 Some math library functions 7 Some math library functions Using math library import math Prefix function name with math. 8 Explicit type conversion Force int to float or float to int 9 Rounding Allows specifying the number of decimal places 10 1-D array of numbers [element , element 1 , , elemen n-1 ] 0-based indices len function returns length of array, i.e. the number of elements (n) 11 Traversal of 1-D array, version 1 12 Using for loop Directly on elements Traversal of 1-D array, version 2 13 Using range function Traversal of 1-D array , version 2 14 Using range function and for loop on index SortMin in Python 15...
View Full Document

This note was uploaded on 02/27/2012 for the course CS 177 taught by Professor Staff during the Spring '08 term at Purdue University-West Lafayette.

Page1 / 15

PythonNumbersAnd1DArraysofNumbers - approximate, the...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online