Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The problem is: Programming Projects: Please use case scenario work out this que

ID: 670719 • Letter: T

Question

The problem is:

Programming Projects:

Please use case scenario work out this question.

Caffeine Absorption. After caffeine is absorbed into the body, 14% is eliminated from the body each hour. Assume a person drinks an 8-oz cup of brewed coffee containing 146 mg of caffeine, and the caffeine is absorbed immediately into the body. Write a program to compute the following values. See Fig. 6.12. (Just use Python write input and output, no GUI is needed).

The number of hours required until 73 mg (one-half the original amount) remain in the body.

The amount of caffeine in the body 24 hours after the person drinks the coffee.

Suppose the person drinks a cup of coffee at 7 a.m. and then drinks a cup of coffee at the end of each hour until 7 a.m. the next day. How much caffeine will be in the body at the end of the 24 hours?

Note:

For simplicity, this caffeine absorption is very similar to half life of isotop: (Please do not get confused, as isotope is use half life, that is 50%, and this caffeine aborption rate is 14% eliminate from the body.)

My attempt:

#*************************************************************************
#PROGRAM PURPOSE
#*************************************************************************
"""
a. Find: The number of hours required until 73 mg
(one-half the original amount) remain in the body.

b. Find: The amount of caffeine in the body 24 hours
after the person drinks the coffee.

c. Solve: Suppose the person drinks a cup of coffee at 7 a.m.
and then drinks a cup of coffee at the end of each hour
until 7 a.m. the next day. How much caffeine will be in the
body at the end of the 24 hours?"""

#*************************************************************************

#1----------------------------------------------------------------------
caf = input("How many mg of caffeine were consumed? A cup is 146 mg. ")
c = int(caf)

#find amount of hours until half the caffeine is left

#'h' is hours after absorbtion and 'a' is the resulting caffeine
#after number of hours passed
h = 1
a = c - (.14*h*c)

#use while loop to make a approach 1/2 of starting caffeine
while a > (.5*c):
h = h+1
a = c - (.14*h*c) #keep adding hours to equation until statement is true

print(h, "approximate hours until half the caffeine is absorbed.")

#B-----------------------------------------------------------------------
while h!=24 and a>=0: #make hours have to be 24 and a stay above zero
h = h+1
a = c - (.14*h*c)

print(a, "mg of caffeine are left after 24 hours.")

#C-----------------------------------------------------------------------
total_caf = input("How many mg of caffeine are you drinking per hour for the next 24 hours? A cup is 146 mg. ")
c = int(total_caf)

h = 1
a = c - (.14*h*c)

while h!=24:
h = h+1
a = a+146
a = c - (.14*h*c)
  

print(a," mg of caffeine are in your body after consuming", c,"mg of caffeine every hour for 24 hours. ")

Where did I go wrong? I'm having a lot of trouble in both the math and code.

Explanation / Answer

Dim mg As Double = 146 Dim hours As Integer = 1 'Question A Do mg = mg - (mg * 0.14) hours += 1 Loop Until mg < 73 TextBox1.Text = CStr(hours - 1) & " hours" 'Question B mg = 146 hours = 1 Do Until hours > 24 mg = mg - (mg * 0.14) hours += 1 Loop TextBox2.Text = CStr(mg) & "mg" 'Question C mg = 146 hours = 1 Do mg = mg - (mg * 0.14) hours += 1 mg = mg + 146 Loop Until hours > 24 TextBox3.Text = CStr(mg) & "mg"