Challenge
Strings don't change
code[0] = "X" stops with a TypeError, because Python strings can't be changed. Predict the crash, find out what methods and slices really give, build a new string instead, then swap a letter in the…
Showing 21–30 of 34
Challenge
code[0] = "X" stops with a TypeError, because Python strings can't be changed. Predict the crash, find out what methods and slices really give, build a new string instead, then swap a letter in the…
Challenge
An operator types 42,5 and float() crashes with a ValueError. Predict it, find out why, accept both commas and dots with replace(), then read pressures written like 1 013,25.
Challenge
A crew count read with input() crashes when 1 is added to it. Predict the crash, find out what input() really returns, fix it with int(), then write a packing tool that reads two numbers.
Challenge
A trajectory total adds a leg in miles to legs in kilometres. Predict the total, find the leg that doesn't fit, convert it with a named constant, then convert a lander's feet per second to metres.
Challenge
An average of three hull temperatures comes out at 47 °C when every sensor reads about 21. Predict it, find where the brackets are missing, fix it, then work out an average speed.
Challenge
Predict 0.1 + 0.2, see the 0.30000000000000004 that every programmer meets once, then round it for display the way fuel gauges and dashboards do.
Challenge
Turn the bare 9.81 and 1000 in a weight report into named constants without changing the output, then write a Mars version with constants from the start.
Challenge
A cargo calculation uses a, b, x2 and tmp. Predict it, work out what each name holds, rename them so the code explains itself, then write a fuel check with good names.
Challenge
Two sensor readings add up to 12080 instead of 200 because they arrived as text. Predict it, find out why and fix it with int(), then add decimal readings with float().
Challenge
int() cuts the decimals off, round() rounds, and round(2.5) gives 2. Predict the difference, investigate Python's rounding rule, then round a fuel reading two ways.