In: Computer Science
PYTHON!!!
Radioactive materials decay over time and turn into other substances. For example, the most common isotope of uranium, U-238, decays into thorium-234 by emitting an alpha-particle. The rate of radioactive decay of a material is measured in terms of its half-life. The half-life of a material is defined to be the amount of time it takes for half of the material to undergo radioactive decay. Let m be the initial mass in grams of some material and let h be the material’s half-life in days. Then the remaining mass of the material on day t, denoted m(t), is given by the formula: m(t) = m × 0.5 t/h
Note: This formula is not a Python assignment statement! It is an equation that says: if you know the quantities m, t, and h, you can calculate a value using the right side of the equation. That value will be the amount of remaining mass of the material after t days. For this question, write a program which does the following: • Prompt the user to enter the initial mass of the material (in grams). You must make sure that the user enters a positive number. If they do not enter a positive number, print a message informing them so, and prompt them to enter the initial amount of material again. Keep doing this until they enter a positive number. • Prompt the user to enter the half-life of the material (in days). As above, make sure that the user enters a positive number, and if they don’t, keep asking until they do. • Starting from day 0, output the amount of the material remaining at one-day intervals. Thus, for day 0, day 1, day 2, etc., you should print out the amount of remaining mass according to the above formula. Your program should stop on the first day on which remaining mass is less than 1% of the initial mass. Don’t forget to import the math module if you need math functions. Hint: A correct solution should make use of three while-loops.
Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. Let me know for any help with any other questions. Thank You! =========================================================================== import math def main(): print(' *** Radioactive Decay Table ***') mass = 0 while mass<=0: mass = float(input('Enter the intial mass of the material (in grams): ')) if mass <= 0: print('Error: Mass cannot be zero or negative. Please re-enter.') half_life = 0 while half_life<=0: half_life = float(input('Enter half-life of the material (in days): ')) if half_life <= 0: print('Error: Half-Life cannot be zero or negative. Please re-enter.') print('{:<10}{:<20}'.format('Day#', 'Mass Remaining (in grams)')) day = 0 initial_mass = mass while True: print('{:<10}{:^20.4f}'.format(day, mass)) day += 1 mass = mass * (0.5 ** (day / half_life)) if (mass) / initial_mass < 0.01: break if __name__ == '__main__': main()
==================================================================