Ask Question
20 April, 23:17

In Coral programming: A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has a half-life of about 6 hours in humans. Given caffeine amount (in mg) as input, output the caffeine level after 6, 12, and 18 hours.

Ex: If the input is 100, the output is:

After 6 hours: 50.0 mg

After 12 hours: 25.0 mg

After 18 hours: 12.5 mg

Note: A cup of coffee has about 100 mg. A soda has about 40 mg. An "energy" drink (a misnomer) has between 100 mg and 200 mg.

+1
Answers (1)
  1. 21 April, 00:30
    0
    Yes, it will be after 6 hours: 50 mg, after 12 hours: 25 mg, and after 18 hours: 12.5 mg

    Explanation:

    Remember coral is a functional programming language and follows Pythons functional programming paradigm. Remember Python supports functional, imperative as well as OOPS paradigm.

    The function will be:

    def void calcamtleft (int amt):

    integer a=6

    integer time=6

    integer i=1

    while amt> 0:

    amt=amt/2

    print ("After"+time+" hours:" + amt+"mg")

    i++

    time=a * i

    Hence in first loop amt=100

    new amt=100/2=50

    After 6 hours: 50 mg (this will be printed)

    i will increment then, and time will be = 6 * 2 = 12

    now input amt=50

    new amt=50/2=25

    After 12 hours 25 mg (this will be output)

    i will increment then, and time will be = 6 * 3 = 18

    now input amt=25

    new amt=25/2=12.5

    After 18 hours 12.5 mg (this will be output)

    i will increment then, and time will be = 6 * 4 = 24

    now input amt=12.5/2 = 6.25

    new amt=6.25/2 = 3.125

    After 24 hours 3.125 mg (this will be output)

    i will increment then, and time will be = 6 * 5 = 30

    now input amt=3.125

    new amt=3.125/2 = 1.5625

    After 30 hours 1.5625 mg

    And this will continue till amt>0
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “In Coral programming: A half-life is the amount of time it takes for a substance or entity to fall to half its original value. Caffeine has ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers