Interactive, runnable Python. Edit the code, run it in your browser, no setup required.
You will write three functions about the hot early universe. The idea. The CMB is at 2.725 K today and its temperature is 2.725(1 + z) kelvin at redshift z. Wien's law gives the peak, λ = 2.898 × 10^-3/T metres. The c…
You will write two functions about sulphuric acid: one names the property a reaction shows, the other finds the alkali for a dibasic acid. The idea. A reaction that gives a salt with a metal, oxide, hydroxide, carbona…
You will write the income and the return of a holding, then use them to judge a switch from one share to another. Your tasks. In income, return the number of shares times the rate of dividend (as a fraction) times the…
You will plan the fuel of a migrant, predict the error of a clock-shifted bird, and follow a clock that runs free. The idea. The fat needed is the power times the flight time, divided by 39 000 J per gram. The flight…
You will fit a sine to 60 noisy readings of a swinging spring, with a first guess from the FFT. The idea. The FFT finds the main frequency to within one bar. curve_fit then refines the amplitude, the frequency and the…
You will build the whole method for quarterly data: centred moving averages, seasonal components and a forecast. The idea. Centre the 4-point averages by taking the mean of each neighbouring pair. The first centred va…
You will turn an output column into a logic expression by the method of the lesson: one AND term for each row with X = 1, joined by OR. Your tasks. In term, return the AND term for one row. An input that is 1 is writt…
You will write three small functions about the density of the Universe. The idea. The critical density is ρ_c = 3H_0^2/(8π G) with H_0 in s^-1. A value in km/s per Mpc is changed to s^-1 by dividing by 3.086 × 10^19.…
You will work out the terms of trade of a country that exports coffee, year by year, and find how much more coffee it must sell to keep buying the same imports. The idea. Terms of trade = export price index import pri…
You will write three functions about the expansion of the universe. Speeds are in km/s, distances in Mpc. The idea. For small redshifts v = cz, with c = 3.00 × 10^5 km/s. Hubble's law is v = H_0d. The Hubble time is 1…
You will write three functions that follow the nitrogen atoms through the Ostwald process. The idea. Step 1: 4NH_3 + 5O_2 → 4NO + 6H_2O. Step 2: 2NO + O_2 → 2NO_2. Step 3: 4NO_2 + 2H_2O + O_2 → 4HNO_3. Each step keeps…
You will write three functions about buying shares and test them on the lesson: ₹15 000 in ₹100 shares at ₹125. Your tasks. In shares_bought, return the number of whole shares the money buys. Use //. In premium, retur…
You will rank prey by profitability and find the best time to stay in a patch that runs down. The idea. Profitability is E/h. In a patch the gain after t seconds is G(1 - e^-t/k), and the rate over a trip is the gain…
You will draw a wave of wavelength 3.0 m and frequency 4.0 Hz at two times, find its first crest each time, and work out its speed. The idea. The crest of y = A(kx - ω t) moves at the speed v = fλ. You find where the…
You will write a function that finds the moving averages of a time series for any number of points, and use it to see which length removes a seasonal swing. The idea. A k-point moving average is the mean of k values i…
You will code the circuit X = (A AND B) OR (NOT C) and build its truth table in the syllabus order. Your tasks. In circuit, return X for the inputs a, b and c. Set rows to the 8 input rows (a, b, c) in binary order. S…
You will write three small functions about the microwave background. The idea. Wien's law gives the peak wavelength λ_ = 2.898 × 10^-3/T in metres. When space was S times smaller, the glow was S times hotter. The stre…
You will follow the amounts of three ozone-depleting gases in the air after their emissions stop, and find when each one falls below a target. The idea. A gas with a lifetime of τ years falls as N = N_0e^-t/τ The amou…
You will write three functions that astronomers use to find and measure planets. Masses are in solar masses, distances in AU, times in years. The idea. Kepler's third law in these units is M = a^3/T^2. A transit of de…
You will write a small identifier for metal ions, using what ammonia solution does to their solutions, and a calculator for the nitrogen in a fertiliser. The idea. Ammonia solution gives a precipitate with each of the…
You will write two functions that read the RD formula backwards. Your tasks. In instalment, return P = (MV)/(n + (n(n + 1))/(24) × (r)/(100)). In months, start at n = 1 and add 1 while the interest is still less than…
You will work out the relatedness of worker bees, test Hamilton's rule, and find how safe a flock is. The idea. Two workers whose mother mated with n males have an average relatedness of 0.25 + 0.5/n. Helping is favou…
You will write three small functions that check a claimed identity on many angles: one finds the worst miss between the two sides, one says whether the identity holds, and one finds an angle where it fails. The idea.…
You will build a small cost of living index from what a household bought in the base year. The idea. Each weight is the base-year spending: quantity × base-year price. The index is Σ (w × price relative)Σ w. The cost…
You will write a function that names a two-input gate from its output column, and a function that builds the 8 rows of a three-input truth table in order. Your tasks. In name_gate, return the name of the gate in GATES…