# Banana calculator

Posted on 13th Sep 2017

I made a simple script which translates a selection of radiation exposures to a estimated amount of bananas. Even though the result is quite basic it was fun to build!

My startingpoint was a very basic calculation script using a HTML form and PHP calculation I came across.

<html>
<title>A simple math calculator</title>
<body>
Insert two numbers in the next form and hit submit button <br>
<form action="calculation.php" method="post">
Firstnumber: <input name="num1" type="text" /><br>
Secondnumber: <input name="num2" type="text" />
<input type="submit" />
</form>
</body>
</html>

This form gives to option to input two numbers which are defined with a name. After submitting the results are calculated by in a PHP script.

<html>
<title>Simple Math With User Input</title>
<body>
<?php
\$num1 = \$_POST['num1'];
\$num2 = \$_POST['num2'];
\$a = \$num1 + \$num2;
\$b = \$num1 - \$num2;
echo "The sum of the two numbers is ". \$a;
echo "The difference of the two numbers is ". \$b;
?>
</body>
</html>

With this as my starting point I managed to create a new form which gives the response on the same page.

<html>
<title>A simple banana calculator</title>
<body>
Select a radiation exposure and the preferred banana size for it to be expressed in.<br>
<form action="" method="post">
<fieldset>
<legend>Dose in bananas</legend>
Type of exposure:<br>
<select name="Exposure">
<option value="40">Thorax x-ray</option>
<option value="55">One day visit to Chernobyl</option>
<option value="70">Flying (NYC-London)</option>
<option value="13000">CT Abdomen</option>
</select>
<br>
Size of banana:<br>
<select name="Banana">
<option value="0.080">Small</option>
<option value="0.090">Medium</option>
<option value="0.098">Large</option>
</select>
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>

<?php
\$exposure = \$_POST['Exposure'];
\$banana = \$_POST['Banana'];

\$a = round (\$exposure / \$banana);
\$b = round ((\$a/365),2);

echo "Your exposure equals roughly ". \$a ." bananas.";

echo "<br/> Or roughly ". \$b ." bananas per day for a year.";

?>

</body>
</html>

The form gives you seven options which al have a rough dose value in micro Sieverts. For of these options are represented as exposure types and three as banana sizes (I wanted to put in something..). After submitting the HTML form a PHP script is run to find the quotient of the exposure dose and the bananas dose (\$a). Additionally the amount of banana’s per day over a year is calculated (\$b).

The result might not be impressive for experienced coders but I leaned something new anyway ;)