Question

Expected Value Notes WhenExpired(4.0) should return 6 16 WhenExpired(0.5) should return 16 1 WhenExpired(55.5) should returnA drug loses decayrate percent of its potency every month. Also, a drug is considered expired if it loses more than 50% potency. Your goal is to write a function WhenExpired(decayrate) that returns the number of months after which the drug is considered expired.

Question 1 [20 points] A drug loses decayrate percent of its potency every month. Also, a drug is considered expired if it lo

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The code is defined as follows:

def WhenExpired(decayrate):
    value = 100.0; #initial value is 100
    months = 0.0;
    decrease = 0.0;
    while value>50.0 and decayrate<100 and decayrate>0: #as per given conditions is decayrate is larger than 100 or decayrate is negetive, no.of. months is zero
        decrease = value * decayrate/100; #the decrease in potency can be computed by multiplying the current value by decayrate
        value = value - decrease; # decrement the value by the decrease amount
        months = months + 1; #increment the number of months for every decrease
    return months #return the months

month = WhenExpired(4);
print("The no.of months = ",month);

to decayexample.py - D:\NMAMIT Nitte Chegg Answers\decayexample.py (3.8.2)* - 0 X Eile Edit Format Run Options Window Help de

For Input of 12.0, the output is:

Le Python 3.8.2 Shell - 0 x File Edit Shell Debug Options Window Help Python 3.8.2 (tags/v3.8.2:7b3ab59, Feb 25 2020, 23:03:1

This can be justified with mathematical calculations also.

Initially value = 100

At the end of 1st month, value = 100*(1-12/100) = 88

At the end of 2nd month , value = 88*(1-12/100) = 77.44

At the end of 3rd month , value = 77.44*(1-12/100) = 68.15

At the end of 4th month , value = 68.15*(1-12/100) = 59.97

At the end of 5th month , value = 59.97*(1-12/100) = 52.77

At the end of 6th month , value = 52.77*(1-12/100) = 46.44

At the end of 6th, the value has come below 50% hence the expiry will be after 6 months.

Please do check the values given in the table and revert back in case of any doubts.

Add a comment
Know the answer?
Add Answer to:
A drug loses decayrate percent of its potency every month. Also, a drug is considered expired...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write prescription for signature by the physician. check drug reference to be sure the dosage is...

    write prescription for signature by the physician. check drug reference to be sure the dosage is appropriate. if dosage is incorrect, make note of that fact. 32. Dr. Merry wants Mary Doe to take nitroglycerin tablets 0.4 mg sublingually every 3 min for chest pain. He wants her to have 100 table 1. he wants her to have 100 tablets. This site may be filled as needed, but after the bottes opened, it should be refilled every 6 months to...

  • in C++ and also each function has its own main function so please do the main...

    in C++ and also each function has its own main function so please do the main function as well. Previously when i asked the question the person only did the function and didn't do the main function so please help me do it. 1-1. Write a function that returns the sum of all elements in an int array. The parameters of the function are the array and the number of elements in the array. The function should return 0 if...

  • Solve This Problem using python and please comment on every line. also, use function to solve...

    Solve This Problem using python and please comment on every line. also, use function to solve this. thanks The result will be like as below: Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following functions in the program: This function should accept five test scores as arguments and return the average of the scores. This function should accept a...

  • 18. In the month of October, candy production increases by a 7% every day until the...

    18. In the month of October, candy production increases by a 7% every day until the 51 September, the total candy produced is 1.2 million per day. How much candy is made company meet a quota of 10 million by the end of the month? s by a 7% every day until the 31" of the month. At the end of r day. How much candy is made on October 31"? Can a 19. Every 5 years the price of...

  • C++ exercises During the tax season, every Friday, the J&J accounting firm provides assistance to people...

    C++ exercises During the tax season, every Friday, the J&J accounting firm provides assistance to people who prepare their own tax returns. Their charges are as follows: If a person has low income (<= 25,000) and the consulting time is less than or equal to 30 minutes, there are no charges; otherwise, the service charges are 40% of the regular hourly rate for the time over 30 minutes. For others, if the consulting time is less than or equal to...

  • The Heinlein and Krampf Brokerage firm has just been instructed by one of its clients to invest $...

    The Heinlein and Krampf Brokerage firm has just been instructed by one of its clients to invest $250,000 of her money obtained recently through the sale of land holdings in Ohio. The client has a good deal of trust in the in¬vestment house, but she also has her own ideas about the distribution of the funds being invested. In par¬ticular, she requests that the firm select whatever stocks and bonds they believe are well rated, but within the following guidelines:...

  • 4. Find the following: a. b. The unit price varies depending on the specified quantity, and...

    4. Find the following: a. b. The unit price varies depending on the specified quantity, and your goal is to write a formula in cell B9 that calculates the total price for any amount of items input in a specific cell (in this case, cell B8) 1 Unit Quantity 2 1 to 10 3 11 to 19 4 20 to 49 5 50 to 100 6 Over 100 7 8 Quantity 9 Total Cost Price Per Unit 20.00 28.00 16.00...

  • Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing...

    Write a C++ program that demonstrates use of programmer-defined data structures (structs), an array of structs, passing an array of structs to a function, and returning a struct as the value of a function. A function in the program should read several rows of data from a text file. (The data file should accompany this assignment.) Each row of the file contains a month name, a high temperature, and a low temperature. The main program should call another function which...

  • Python Issue Postfix notation (also known as Reverse Polish Notation or RPN in short) is a...

    Python Issue Postfix notation (also known as Reverse Polish Notation or RPN in short) is a mathematical notation in which operators follow all of its operands. It is different from infix notation in which operators are placed between its operands. The algorithm to evaluate any postfix expression is based on stack and is pretty simple: Initialize empty stack For every token in the postfix expression (scanned from left to right): If the token is an operand (number), push it on...

  • Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank...

    Write a program that demonstrates use of programmer - defined data structures. Please provide code! Thank you. Here are the temps given: January 47 36 February 51 37 March 57 39 April 62 43 May 69 48 June 73 52 July 81 56 August 83 57 September 81 52 October 64 46 November 52 41 December 45 35 Janual line Iranin Note: This program is similar to another recently assigned program, except that it uses struct and an array of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT