mercredi 13 février 2019

Why does this while loop execute but produce the incorrect answer?

I am new to python and stackoverflow. I am trying to learn by working on small projects

Cobalt-60, a radioactive form of cobalt used in cancer therapy, decays over a period of time. Each year, 12% of the amount present at the beginning of the year will have decayed. If a container of cobalt-60 initially contains 10 grams, determine the amount remaining after five years.

The code that I have used is:

year = 0
cobalt_life = 10
while cobalt_life == 10:
      cobalt_life -= 0.12*cobalt_life
      year +=5
print(cobalt_life)

However,the output is 8.8 when i run this. What am I missing? The output I desire is

The amount of cobalt-60 remaining after five years is 5.28 grams.

Aucun commentaire:

Enregistrer un commentaire