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