Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python w PyCharm - Purpose: To practice using loops to repeat actions until a condition is met (and solve a practical problem at the same

Python w PyCharm

-

image text in transcribedimage 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, the most commorn 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 mass of the material remaining on day t, denoted m(t), is given by the formula: m(t) mx0.5t/h Note This formula is not a Python assignment statement! It is an equation that says that, if 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 folloing Prompt the user to enter an initial amount of a 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 O, output the amount of the material remaining on one-day intervals. Thus, for day 0, 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 original mass of material remaining 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 -7 Error! Half life must be a positive number Enter half life in days2 Enter initial amount of material in grams: 100 After 0 days there are 100.0 grams remaining After 1 days there are 70.71067811865476 grams remaining After 2 days there are 50.0 grams remaining After 3 days there are 35. 35533905932738 grams remaining After 4 days there are 25.0 grams remaining. After 5 days there are 17.67766952966369 grams remaining After 6 days there are 12.5 grams remaining After 7 days there are 8.838834764831844 grams remaining After 8 days there are 6.25 grams remaining After 9 days there are 4.419417382415922 grams remaining After 10 days there are 3.125 grams remaining After 11 days there are 2.209708691207961 grams remaining After 12 days there are 1.5625 grams remaining. After 13 days there are 1.1048543456039805 grams remaining After 14 days there are 0.78125 grams 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 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 = 2 and m-100 and make sure the output is identical to the sample output. Then test your program with h-1 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

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions