Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Purpose: To practice using loops to repeat actions until a condition is met (and solve a practical problem at the same time!). Degree of Difficulty:

image text in transcribed

image text in transcribed

Purpose: To practice using loops to repeat actions until a condition is met (and solve a practical problem at the same time!). Degree of Difficulty: Easy Radioactive materials decay over time and turn into other substances. For example, Carbon-14 decays into Nitrogen-14 through beta decay. 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 4, denoted m(t), is given by the formula: m(t) = m x 0.5t/ Note: This formula is not a Python assignment statement. It is an equation that says if you know the quantities m. I, 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 I days. For this question, write a program which does the following: Prompt the user to enter the initial mass of the material Gin 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 o output the amount of the material remaining at one-day intervals. Thus, for day o. 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. Sample Run Sample input and output (input typed by the user is shown in green text): Enter half life in days: -13 Error! Ha If life must be a positive number. Enter half life in days: 0 Error! Half life must be a positive number. Enter half life in days: 3 Enter initial amount of material in grams: 80 Ifter 0 days there are 80.0 grams remaining Ifter 1 days there are 63.4960420787 2798 grams remaining ifter 2 days there are 50.396 8419 9 5794 93 grams remaining After 3 days there are 40.0 grams remaining After 4 days there are 31.7480 2103936399 grams remaining. After 5 days there are 25. 1984 209 97 89 7 4 6 5 grams remaining After 6 days there are 20.0 grams remaining Ifter 7 days there are 15.87401051968 1994 grams remaining After 8 days there are 12.599 2104 98 94 873 2 grams remaining After 9 days there are 10.0 grams remaining After 10 days there are 7.93700 5259840997 grams remaining Ifter 11 days there are 6.299 60 524 9474 366 grams remaining. After 12 days there are 5.0 grams remaining Ifter 13 days there are 3.96 850 26 29 9 2049 97 grams remaining. Ifter 14 days there are 3. 14980 26 24 737 182 grams remaining. Ifter 15 days there are 2.5 grams remaining Ifter 16 days there are 1.98 4 2513 14 960 2499 grams remaining Ifter 17 days there are 1.57 4 9 0 13 1 236 8 591 grams remaining After 18 days there are 1.25 grams remaining. Ifter 19 days there are 0.99 21 2 56 57 4801 249 grams remaining. Ifter 20 days there are 0.7874 506 56 18 4 29 55 grams remaining. Note how the half-life in this example was 3 days, and that indeed, after 3 days, half of the original 80 grams of material decayed and we were left with 40 grams. Further note how after an additional 3 days, on day 6, half of the 40 grams remaining on day 3 decayed leaving us with 20 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 = 3 and m = 80 and make sure the output is identical to the sample output. Then test your program with h = 2 and m = 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

2. What do you believe is at the root of the problem?

Answered: 1 week ago