Real-world case: One number in the wrong type: the first flight of the Ariane 5 rocket, 1996
4 June 1996 · the uncrewed first flight of a European launch vehicle
On 4 June 1996 the first Ariane 5 rocket lifted off from French Guiana. About 37 to 40 seconds later it veered off course, broke up and exploded. An independent inquiry board found the cause in the software of the inertial reference system, which tells the rocket where it is and how it is moving.
The software converted a number describing the rocket’s horizontal velocity from a 64-bit floating-point value (a decimal number held with great range) into a 16-bit signed integer (a whole number that cannot exceed 32,767). On this rocket the value was larger than the integer could hold, so the conversion failed, and the system shut down and passed an error message on as if it were data. The code came from the earlier Ariane 4, where its values had stayed within range.
Nothing was wrong with the idea of the program. A value of one type was forced into a smaller type without checking that it would fit.
How the case shows what you learned in this module
| Module idea | In the case |
|---|---|
| A program is exact instructions (Lesson 1) | The computer did exactly what it was told. It did not guess that the number should have fitted. |
| Variables and assignment (Lesson 2) | A variable holds one value of one kind. Storing the velocity value in a smaller variable changed what could be held. |
| Numbers and arithmetic (Lesson 3) | Decimals and whole numbers are different types, and whole-number types have limits. Rounding and range matter. |
| Text, input and conversion (Lesson 4) | Converting between types (as with int() on text from input()) is a step that can fail, so it must be checked. |
Workplace takeaway. When a script converts a value from one type to another, such as a typed quantity into a whole number, test it with extreme values (very large, zero, negative, blank). Reusing code from an older project is safe only if the new inputs fit the old assumptions.
Sources: Report by the Inquiry Board on Ariane 5 Flight 501 (Paris, 19 July 1996), chaired by J. L. Lions; summary at the University of Minnesota disasters archive (Arnold); entry on Ariane flight V88.
Discussion prompt
20 minutes. Think of a small, repeated task in your study or work that a program could do. In 150 to 200 words, state its input, its output, and which of the ideas from this module (variables, arithmetic, text, input) it would use.
Private: nothing you type here is sent or stored.
This course has no discussion board yet, so the prompt is a private reflection.
Recap
- A program is exact instructions in order; print() shows output.
- A variable is a name for a value; = stores it.
- / gives a decimal, // the whole part, % the remainder; brackets override order.
- input() returns text; convert it with int() before calculating.
Flashcards: 12 workplace review cards
Tap a card to reveal the answer. Read the question, answer it aloud or in writing first, then check yourself against the explanation.
Card 1 of 12 · A colleague says their script printed 'Total: 36' but they wanted the numbers added. What do you check first?
Check the type of each value. Text joins with + and numbers add. If the values came from input() they are strings, so "3" + "6" gives 36, not 9. Convert with int() or float() before calculating.
At work: any report that reads quantities from a form, a file or a typed prompt must convert them first, or totals will be joined text.
Card 2 of 12 · What does a program do, and why must instructions be exact?
A program is a list of instructions that the computer follows from top to bottom, exactly as written. It does not guess your intention, so a missing quotation mark or a misspelt name stops it. This is why programs are dependable: the same instructions give the same result every time.
At work: an automated invoice script will repeat one wrong instruction on every invoice, so test it on a small sample first.
Card 3 of 12 · Your script crashes with a long error message. Which line do you read first?
Read the last line of the error first. It names the kind of error (such as NameError or TypeError) and says what went wrong. The lines above show the route the program took to get there, which helps you find the place.
At work: when you ask a colleague for help, send the last line and the line number, not a screenshot of everything.
Card 4 of 12 · What does the line total = price * count store, and when is it calculated?
The equals sign means store the value on the right under the name on the left. Python works out price * count at that moment and stores the result. If price changes later, total does not update by itself; you must run the calculation again.
At work: in a pricing script, recalculate totals after every change to a price or quantity.
Card 5 of 12 · What does count = count + 1 mean, and where would you use it?
It reads the old value of count, adds one, and stores the new value under the same name. It is the standard way to keep a running tally.
At work: counting how many orders were processed, how many rows were skipped, or how many attempts a login has had.
Card 6 of 12 · A sales commission is 8 percent of a sale of 2,500. How do you write it, and what comes out?
sale = 2500, rate = 0.08, commission = sale * rate, then print(commission) shows 200.0. Percentages are stored as decimals, so 8 percent is 0.08. Naming the values makes the script readable and easy to change when the rate changes.
At work: keep rates in named variables at the top of a script so that a change is made in one place.
Card 7 of 12 · How do you find how many full boxes of 12 you can fill from 100 items, and how many are left over?
Use whole-number division and the remainder: 100 // 12 gives 8 full boxes and 100 % 12 gives 4 left over. The ordinary / gives the decimal 8.33..., which is not useful when you cannot ship part of a box.
At work: packing, shift rotas, batch sizes and splitting costs into equal groups all use these two operators.
Card 8 of 12 · Why does 0.1 + 0.2 not print exactly 0.3, and should you worry?
Decimals are stored approximately in binary, so tiny rounding differences appear (0.30000000000000004). For most reports this does not matter if you round for display. For money, keep amounts in whole pence or cents, or use a decimal type, so that totals match to the penny.
At work: reconcile payments in integer pence and format only when printing.
Card 9 of 12 · What is the order of operations in 2 + 3 * 4 ** 2, and what is the result?
Power first, then multiplication and division, then addition and subtraction; brackets override. Here 4 ** 2 = 16, then 3 * 16 = 48, then 2 + 48 = 50. When a formula looks unclear, add brackets to show your intent.
At work: a wrong bracket in a discount formula can overcharge every customer, so check one calculation by hand.
Card 10 of 12 · How do you print a friendly message using a name and a total?
Use an f-string: print(f"Hello {name}, your total is {total}"). The parts in curly brackets are replaced by the values. It is clearer than joining pieces with + and it avoids the error of adding text to a number.
At work: automatic emails, receipts and log messages are usually written with f-strings.
Card 11 of 12 · What is a TypeError, and how do you fix "Total: " + 36?
A TypeError means an operation was used on the wrong kinds of value; here text and a number cannot be added. Fix it by converting the number to text with str(36) or by using an f-string.
At work: read the error, find the two values and their types, and convert one of them.
Card 12 of 12 · A user types their age. Why does age + 1 fail, and what is the fix?
input() always returns a string, even if the user typed digits. Adding 1 to a string raises a TypeError. Convert first: age = int(input("Age: ")). If the user might type letters, plan to check or handle that case, which later modules cover.
At work: every form or prompt that collects a number needs a conversion step.
Module notes
Key terms. Program: a list of instructions. Variable: a name for a value. Assignment: storing a value with =. String: text. f-string: a string with calculated parts in curly brackets. TypeError: an operation on values of the wrong type.
Rules and formulas. whole parts = a // b; remainder = a % b; a = (a // b) * b + (a % b).
Limits of this module. Examples use Python 3 and are short. The expected outputs shown follow the documented behaviour of the language; run them to confirm.
Next
Continue to Module 2: Decisions: Comparison and if Statements. You can also return to the course overview or the University Track.
References and further reading
- Python Software Foundation. The Python Tutorial and The Python Language Reference (documentation for Python 3), available from python.org.
- Specialty Digest encyclopedia: Programming Language, Algorithm, Object-Oriented Programming and Binary Search.