The MagPi Issue 7

Page 28

Defensive Bases This month we are having a go at some "defensive programming"; in other words trying to write a program that can handle errors. This converts a number from denary into the output base, getting the digits from the string "DIGITS" (see next page).

Sorry the scripts are in a funny order this month - space is tight!

The "get_base" Script This part of the code allows you to set the input and output base for the program to use. It won't allow you to enter a number less than 2 or greater than 16. This will help to avoid some really strange (and incorrect) results.

Hex Joke! If only DEAD people understand hexadecimal, how many people understand hexadecimal?

(answer on next page!)

28


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.