More Variables (Expressions and Variables)
Calculate a total biomass in grams for 3 White-throated Woodrats (Neotoma albigula) and then convert it to kilograms. The total biomass is simply the sum of the biomass of all individuals, but in this case we only know that the average size of a single individual is 250 grams.
- Add a new section to your Python file starting with a comment.
- Create a variable
grams
and assign it the mass of a single Neotoma albigula. - Create a variable
number
and assign it the number of individuals - Create a variable
biomass
and assign it a value by multiplying the two variables together. - Convert the value of
biomass
into kilograms (there are 1000 grams in a kilogram so divide by 1000) and assign this value to a new variable. - Print the final answer to the screen.
Are the variable names grams
, number
, and biomass
the best
choice? If we came back to the code for this assignment in two weeks
(without the assignment itself in hand) would we be able to remember
what these variables were referring to and therefore what was going on
in the code? The variable name biomass
is also kind of long. If we
had to type it several times it would be faster just to type b
. We
could also use really descriptive alternatives like
individual_mass_in_grams
. Or we would compromise and abbreviate
this or leave out some of the words to make it shorter (e.g.,
indiv_mass_g
).
Think about this and then rename the variables in your program in whatever you think is most useful.
Expected outputs for More Variables: 1