Challenge
Round or cut?
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.
Showing 1–10 of 124
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.
Challenge
Split a sensor ID like ENG-2 into its subsystem and its unit number as an int, work out the next ID, then handle subsystems with a dash in their name using rsplit().
Challenge
…arrived as text. Predict it, find out why and fix it with int(), then add decimal readings with float().
Challenge
…crash, find out what input() really returns, fix it with int(), then write a packing tool that reads two numbers.
Example
Changing data types using int(), float() and str() functions. Converting between types.
Example
Python recognizes different data types automatically. Learn int, float, str and bool.
Quiz
…on Python type conversion and input(): 15 questions on int(), float(), str(), bool() and reading numbers from the user.
Challenge
Turn a tank's capacity and contents into a fill percentage with one decimal place, then draw the crew display's ten-segment gauge with string repetition and int().
Quiz
Free beginner quiz on Python data types: 15 questions on int, float, str, bool, None, lists, tuples, dictionaries and sets, with instant answers.
Challenge
…and modify Investigate. Every value has a type: int for whole numbers, float for decimals, str for text and bool for True / False . Replace each ... with the type of that value, for example crew_type…