1. Engineering
  2. Computer Science
  3. language python 3...

Question: language python 3...

Question details
Language: python 3
Question 3 (7 points) Purpose: To practice using loops to repeat actions until acondition is met land solve a practical problem at the same time! Degree of Difficulty: Easy 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 ts 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 materials half-life in days. Then the mass of the material remaining on day t, denoted m(t), is given by the formula: Note: This formula is not a Python assignment statement! t is an equation that says that. f you know the quantities m.t, and h, you can calculate a value using the right side of the equation, giving you a quantity that tells you the remaining mass at time t, m(t), which is the left side of the equation Write a program which does the following Prompt the user to enter an initial amount of a material (in grams) You must mae su 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 * that the user 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 dont, keep asking until they do Starting from O, day 1, day 2, etc. you should print out the amount of material remaining according to the above formula. Your program should stop on the first day on which there is less than 1% of the onginal mass of material remaining day 0, output the amount of the material remaining on one-day intervals Thus, for day * Dont forget to import the math module fyou need math functions. Hint: A correct solution should make use of three while-loops. Sample Run Sample input and output input typed by the user is shown in green text Enter half life in days: 7 Error! Half life suat be a positive auber Enter half life in days: 2 Enter initial anount of naterial in grans: 100 After 0 days there are 100.0 grams renaining After days there are 70.71067811865476 gans resaining After 2 days there are 50.0 g% aas re alsing After 3 days there are 35.35533905932738 grans resaiaing After 4 days there are 25.0 grans remaining After 5 days there are 17.67766952966369 grans resaining After 6 days there are 12.5 6rans renaining After 7 days there are 8.838834764831844 gans resaining After 8 day there aze 6.25 grams re alsing After 9 days there are 4.419417382415922 grans renaining After 10 days there are 3.125 grans remaining After 11 days there are 2.209708691207961 grans renaining After 12 days there are 1.5625 grass remaining
After 13 days there are 1.1048543456039805 grans remaining After 14 days there are 0.78125 grans remaining Note how the half-life in this example was 2 days, and that indeed, after 2 days, half of the original 100 grams of material decayed and we were left with 50 grams. Further note how an after an additional 2 days, on day 4, halfofthe 50 grams remaining on day 2 decayed leaving us with 25 grams remaining. This observation should help you determine whether your program is correct for other values of h- after every h days, the amount of material should have decreased by half Testing Test your program with h 2and m 100 and make sure the output is identical to the sample output. Then test your program with 1 andm 100. Make sure the output makes sense! Then test your program once more with inputs of your choice - these should be unique to you and unlikely to be chosen by two different students. Do not use too large a value for h, or your program will produce very long outputs. Copy the console output of your three test runs to a document, and hand it in with your program code (see below).
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution