53.4k views
17 votes
The code needs to be done in Coral

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

1 Answer

8 votes
caffeine_mg = float(input())
six_hours = caffeine_mg / 2
twelve_hours = six_hours / 2
twenty_four_hours = twelve_hours / 4
print('After 6 hours: {:.2f} mg'.format(six_hours))
print('After 12 hours: {:.2f} mg'.format(twelve_hours))
print('After 24 hours: {:.2f} mg'.format(twenty_four_hours))
User Kashyap
by
6.3k points