Question
Python 3 please
Bacteria and Drug Resistance If you dont take all your antibiotics when you are sick, you could be creating super drug resistant bacteria. Create a Bacteria class and run some simulations of results. Classes You will have to implement a couple of classes in this creating the classes with methods as given will help quite a bit when it comes to finishing up this program. The methods given here have to be implemented as given, however, you can add extra methods or attributes as needed. Bacteria When initializing the Bacteria class the resistance is passed in on initialization. However, the resistance may mutate on init by one point either direction, or it may not mutate at all. When passing in a resistance of 5, it might create the bacteria with a resistance of 5,4 or 6. The health attribute is set on init to 10, the life span of the Bacteria is set to 15 and the birth counter is set to 3 >b Bacteria (3) >>> b.birth counter 3 >>> b.health 10 >>> b.life_span 15 >>> b.resistance The resistance cannot be less than 1, and cannot be greater than 10 -str-override The string override should return the string representation of the bacteria. H for Health, R for Resistance, LS for life span and BC for birth counter.
>bBacteria (3) >>> print (b) H(10) R (2) LS(15) BC (3) >bBacteria (3) > print (b) H(10) R(2) LS (15) BC (3) bBacteria (3) >> print (b) H(10) R4) LS (15) BC (3) is alive Method The is alive returns a True or False, True if the Bacteria is alive, False if it is dead. Bacteria is alive only if its health is greater than O, and its life span is > 0 Bacteria (3) b.is alive 0 True b.health-o > b.is alive False > b.health -10 >> b.life span-0 b.is alive False >>b.health O b.is aliveO False tick Method The tick method decrements the birth_ counter by 1 and the life_span by one. >>bBacteria (3) >>> print (b) E(10) R(2) LS (15) BC (3) >>> b.tick ) >>> print (b) E(10) R(2) LS (14) BC(2) dose Method The dose method takes an extra argument the amount to dose the bacteria with medicine by The health is going to be reduced by a fraction of the resistance. damage - dosage x escrance
>>b Bacteria (3) >>>print (b) H(10) R(3) LS (15) BC (3) >>>b.dose (20) >>> print (b) H(3.333333333333333) R(3) IS (15) BC (3) reproduce Method The reproduce method takes no additional arguments, but will return a new Bacteria if the current bacteria is alive and the birth_counter O. It will also reset the birth counter b-Bacteria (3) >b.tick) >b.tick) >>> print (b) 3(10) R(4) L3(13) >>>blb.reproduce >>> bl >>> type (b1) <olass NoneType> ВС (1) >b.tick >>> print (b) H(10) R(4) L (12) BC (O) >>> bl b. reproduce ( ) >>> print (b) LS (12) C (3) (10) R(4) >>> print (bi) H (10) R(4) LS (15) BC (3) Host Class The host class is a person that a collection of bacteria in them. init_ method The init method will take an extra argument that passes in the number of bacteria. The bacteria resistance will initialize to 3. Over time the host can have thousands of bacteria, so youll want to use a data structure that can hold multiple instances str _ method The string method will return a string with 3 lines. The count of how many bacteria there are in the hose, the Average Health of the bacteria, and the Average resistance of the bacterial. >>> h Host (1) >>> print (h) Count :1 Average Health 10.0 Average Resistance : 4.0 tick) Method The tick method has one additional parameter, which is with_dose and is a boolean. If its true
then the bacteria will be dosed. If its false, then the cells wont be dosed. it will call the tick method for all of the bacteria, add any new bacteria from cells that reproduce and remove any cells that have died. The amount of dosage that is used is 25. > hHost (1) >print (h) Count :1 Average Health: 10.0 Average Resistance: 2.0 >>h.tick) >>> h.tick) >>> h.tick) >>> print (h) Count : 2 Average Health:10.0 Average Resistance: 2.0 >>>h.tick (True) >>> print (h) Count : 0 Average Health: nan Average Resistance: nan Specifications . The initial health of bacteria cells is 10 The life span of cells is 15 The birth counter of the cells is initially 3 When dosed the dosage used is 25 . Sample Program There will be 3 hosts that we try. Each starts out with 1 bacteria and runs for 30 ticks, before they discover they have an infection They only vary on the next 15 ticks. The first is a host with no doses, so they really are run for 45 ticks and show the final result. The next is a host that is dosed for the last 15 ticks. This is a fully dosed example. The last is a partially dosed example and only only doses every other round on the last 15 trials. What we expect to see is that our strain in the hosts become more resistant
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import math

import random

class Bacteria:

def __init__(self, resistance):

if(resistance > 10 or resistance < 1):

raise Exception("Invalid resistance")

self.resistance = random.choice(range(resistance-1,resistance+2))

self.health = 10

self.life_span = 15

self.birth_counter = 3

def __str__(self):

return "H({1})\tR({2})\tLS({3})\tBC{4}".format(self.health,self.resistance,self.life_span,self,birth_counter)

def is_alive(self):

return self.health > 0

def tick(self):

self.birth_counter = self.birth_counter - 1

self.life_span = self.life_span - 1

def dose(self,dosage):

self.health = self.health - (dosage * (1/self.resistance))

def reproduce(self):

if self.is_alive() and self.birth_counter <= 0:

self.birth_counter = 0

return Bacteria()

class Host:

def __init__(self,no_of_bacteria):

self.batcteria = list()

for i in range(no_of_bacteria):

self.batcteria.append(Bacteria(3))

def __str__(self):

total_health = 0

total_resistance = 0

for i in self.batcteria:

total_health = total_health + i.health

total_resistance = total_resistance + i.resistance

count = len(self.batcteria)

return "Count : {0}\nAverage health : {1}\nAverage resistance : {2}".format(count,total_health/count,total_resistance/count)

def tick(self,with_dosage=False):

if with_dosage:

for i in self.batcteria:

i.dose(25)

for i in range(len(self.batcteria)):

if self.batcteria[i].is_alive():

self.batcteria.append(self.batcteria[i].reproduce())

else:

del self.batcteria[i]

if __name__ == "__main__":

a = Host(1)

b = Host(2)

c = Host(3)

for i in range(30):

a.tick()

for i in range(15):

a.tick()

b.tick(True)

if(i%2 == 0):

c.tick(True)

else:

c.tick()

print(a)

print(b)

print(c)

OUTPUT :

CODE SCREENSHOTS :

**Please do let me know if you need any futhur assistance. Thank you **

Add a comment
Know the answer?
Add Answer to:
Python 3 please Bacteria and Drug Resistance If you don't take all your antibiotics when you...
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
  • LAB Genetic Engineering of Bacteria Problem Is it possible to transfer the allele for resistance to...

    LAB Genetic Engineering of Bacteria Problem Is it possible to transfer the allele for resistance to the antibiotic ampicillin into a bacterial cell? Objectives After completing this lab, the student will be able to: 1. Demonstrate micropipetting and sterile pipetting techniques for handling and transferring bacteria and plasmid DNA. 2. Maintain sterile conditions for culturing bacterial cells. 3. Inoculate bacteria into flasks, culture tubes, or agar plates. 4. Culture isolated individual colonies from an agar plate to form genetically identical...

  • Hi could you please provide how to do problem 2? Amsterdam University of Applied Sciences Problem 2(15 points) A Wheatstone bridge is used to determine the resistance of a strain gauge. The 3 resista...

    Hi could you please provide how to do problem 2? Amsterdam University of Applied Sciences Problem 2(15 points) A Wheatstone bridge is used to determine the resistance of a strain gauge. The 3 resistances R of the Wheatstone bridge are equal: R 200 12. When the strain gauge is fully relaxed (nd strain present), its resistance Rs is equal to the other 3 resistances: Rs-R. The strain is given bywith AR, the change in resistance in the strain gauge. The...

  • please write these as you would into python. . i will give an thumbs ups 1....

    please write these as you would into python. . i will give an thumbs ups 1. Evaluate the following expressions using Python 1. Product of first 10 even integers. 2. Midterm scores of 4 students are 89, 78, 90, 98. Find the average of these scores. 3. Evaluate 3 to the power 7 4. Find the number of foot in 345 inches. 5. find the remainder when 34567 divides by 17. 2. animals = ['cat', 'dog', 'lion', 'tiger', 'monkey', 'hyena']...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • 1. Bacteria such as E.coll and staph belong to which Domain? A. Animalia B. Eukarya C....

    1. Bacteria such as E.coll and staph belong to which Domain? A. Animalia B. Eukarya C. Archaea D. Bacteria 2. In general terms, prokaryotic cells are cells that? A. Have a nucleus B. Do not have a nucleus. 3. Think about the name E. coli 4X56. In that name which refers to the serotype? A E B. coli C4X56 4. Which of the following best describes the type of bacteria that are important to ecology, and once were thought to...

  • с н А Р Т Е R 2 Microbiology VOCABULARY REVIEW Assignment 27-1: Matching Match the...

    с н А Р Т Е R 2 Microbiology VOCABULARY REVIEW Assignment 27-1: Matching Match the term with its definition and place the corresponding letter in the blank. 1 Culture A Liquid or solid material in which bacteria are grown 2. Agar B. Class of bacteria that do not require axygen to grow 3. Aerobic C. A group of microbes growing on nutrient-rich media 4. Inoculation D. Infection that develops in compromised patients and those taking certain medications such as...

  • I need your help ASAP! please show all work for this activity sheet f True/False Write...

    I need your help ASAP! please show all work for this activity sheet f True/False Write T for true, F for false a) Prostaglandins are used to make steroid hormones b) Prostaglandins are synthesized only in the liver c) Prostaglandins can be used to induce labor d) Prostaglandins are synthesized in the cell only when it is needed e) Prostaglandins prevent the inflammation response Prostaglandins can cause fever and pain sensitivity g) Phospholipids are the only lipids found in a...

  • JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question...

    JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...

  • kindly assist with questions 8,10, 12, 14 and questions 18 and 26 thank you 8) noted...

    kindly assist with questions 8,10, 12, 14 and questions 18 and 26 thank you 8) noted thatc Mars, Inc., the c 8 Checolate An article in Aunat of Nutrition (Vol. 130 No. K nacwsds. The article noees egular consumption of foosds rich in h rist of ovonars hoart drsease" The stuty received Funding from M and the Chovolate Manufacturers Association Sampling Methed. In Kxwrvises 9-12, determine whether the sa 17. Gontsxt of the t ngfal way in which e 8...

  • This assignment is comprised of 3 parts: ​All files needed are located at the end of...

    This assignment is comprised of 3 parts: ​All files needed are located at the end of the directions. Part 1: Implementation of Dynamic Array, Stack, and Bag First, complete the Worksheets 14 (Dynamic Array), 15 (Dynamic Array Amortized Execution Time Analysis), 16 (Dynamic Array Stack), and 21 (Dynamic Array Bag). These worksheets will get you started on the implementations, but you will NOT turn them in. ​Do Not Worry about these, they are completed. Next, complete the dynamic array and...

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