Toggle Navigation
Everything
Blog posts
Pages
Home
About
The Author
The Book
This Website
Book
Chapter 1: Introduction
Chapter 2: The Core Python Language I
Examples
Questions
Problems
Additional Problems
Chapter 3: Simple Plotting with pylab
Examples
Problems
Chapter 4: The core Python language II
Examples
Questions
Problems
Additional Problems
Chapter 5: IPython and IPython Notebook
Examples
Chapter 6: NumPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 7: Matplotlib
Examples
Questions
Problems
Chapter 8: SciPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 9: General Scientific Programming
Examples
Questions
Problems
Errata
Book (2nd ed.)
Chapter 1: Introduction
Chapter 2: The Core Python Language I
Examples
Questions
Problems
Additional Problems
Chapter 3: Simple Plots and Charts
Examples
Problems
Chapter 4: The core Python language II
Examples
Questions
Problems
Additional Problems
Chapter 5: IPython and Jupyter Notebook
Examples
Problems
Chapter 6: NumPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 7: Matplotlib
Examples
Questions
Problems
Chapter 8: SciPy
Examples
Questions
Problems
Additional Examples
Additional Problems
Chapter 9: Data Analysis with pandas
Examples
Problems
Chapter 10: General Scientific Programming
Examples
Questions
Problems
Errata
Additional Notes
Blog
Apps
Contact
Home
Book
Chapter 2: The Core Python Language I
Chapter 2: The Core Python Language I
Examples
E2.1 Numbers in the Python shell
E2.2 Simple mathematical expressions
E2.3 Heron's formula
E2.4 Python's type and id built-ins
E2.5 The return values of logic expressions
E2.6 The "is not" operator
E2.7 Integer object identity gotcha
E2.8 String concatenation with + and *
E2.9 String escaping
E2.10 Unicode
E2.11 String slicing
E2.12 String striding
E2.13 String methods
E2.14 A simple text table using Python strings
E2.15 String representation of integers with comma-separated thousands
E2.16 Using a Python list as a stack
E2.17 Splitting a string
E2.18 Assigning multiple variables in one statement
E2.19 The string join method
E2.20 The Fibonacci sequence
E2.21 The Gregorian calendar
E2.22 Euclid's algorithm for finding the gcd of a number
E2.23 A simple "turtle"
E2.24 Writing numbers to a file
E2.25 Reading numbers from a file
E2.26 Assigning a variable name to a function
E2.27 Default arguments to functions
E.2.28 Function scope
E2.29 The Lazy Caterer's sequence
E2.30 The Tower of Hanoi
Questions
Q2.2.4 Complex numbers: $i^i$
Q2.2.7 Deducing the top-face value of a die
Q2.2.8 Paper folding
Q2.2.10 Exponentiation gotcha
Q2.3.1 String slicing
Q2.3.2 Determine if a string is a palindrome
Q2.3.5 String comparison gotcha
Q2.4.2 Using a list to represent a polynomial
Q2.4.3 Ranking a list
Q2.4.4 The Madhava series
Q2.4.5 any(x) and not all(x)
Q2.4.6 zip and its inverse
Q2.4.7 Sorting one list based on items in another
Q2.5.1 Normalizing a list
Q2.5.2 The arithmetic-geometric mean
Q2.5.3 Fizzbuzz
Q2.5.4 Alkane chemical formulae
Q2.7.2 Compound interest function
Q2.7.3 Harshad numbers
Problems
P2.2
P2.2.1 The XOR operator
P2.2.2 Some fun with the math module:
P2.2.3 The sign function
P2.2.4 Estimating the surface area of the Earth
P2.3
P2.3.1 GC-content of a nucleotide sequence
P2.3.2 String formatting and physical constants
P2.3.3 Formatting a matrix
P2.3.4 Planet symbols in Unicode
P2.4
P2.4.1 Product of all but one integers in a list
P2.4.2 The Hamming distance between strings
P2.4.3 $\pi$ read aloud
P2.4.4 Pascal's triangle #1
P2.4.5 DNA codons
P2.4.6 The double factorial function
P2.4.7 Benford's Law
Stirling's Approximation
Evaluating the Madelung Constant
The Mandelbrot Set
P2.5
P2.5.1 Pascal's triangle #2
P2.5.2 The iterative weak acid approximation
P2.5.3 The Luhn algorithm
P2.5.4 Hero's method for computing a square root
P2.5.5 Determining tomorrow's date
P2.5.6 de Polignac's formula
P2.5.7 The Hailstone Sequence
P2.5.8 The Sieve of Eratosthenes
P2.5.9 Euler's totient function
P2.5.10 Monte Carlo approximation of $\pi$
P2.5.11 Jumbling the letters in each word of a sentence
P2.5.12 Electronic configurations
P2.6
P2.6.1 Analysing redwood species data
P2.6.2 Censoring a text
P2.6.3 Earth Similarity Index
P2.6.4 Manipulating a two-dimensional array
P2.7
P2.7.1 Does a Scrabble word fit?
P2.7.2 A little number problem
P2.7.3 Vector products
P2.7.4 Volume and surface area of a right regular pyramid
P2.7.5 Range and height of a projectile
P2.7.6 An integral of sine and cosine products
P2.7.7 Determine if a string is a palindrome using recursion
P2.7.8 Tetration
Additional Problems
Converting decimal degrees to deg, min, sec
None Converting between an OS grid reference and longitude/latitude