Skip to content

Instantly share code, notes, and snippets.

Created September 13, 2013 19:43
Show Gist options
  • Save anonymous/6555163 to your computer and use it in GitHub Desktop.
Save anonymous/6555163 to your computer and use it in GitHub Desktop.
Premedicant Dose for animal (dog, cat, or rabbit)
"""The Premedicant Dose for animal type is the weight of animal multipled by drug dose_rate, divided by drug concertration."""
class Premedicant_dose(object):
drug_concerntrations = {"metacam" : 5, "synulox" : 32.5, "ketamine" : 100}
rates = {
'dog' : {"metacam" : 0.2, "synulox" : 12.5, "ketamine" : 2},
'cat' : {"metacam" : 0.2, "synulox" : 12.5, "ketamine" : 5},
'rabbit' : {"metacam" : 0.6, "synulox" : "contraindicated", "ketamine" : 20}
}
def __init__(self, species, weight, drug):
self.species = species.lower()
self.weight = float(weight)
self.drug = drug.lower()
def result(self):
if self.rates[self.species][self.drug] == "contraindicated":
return "WARNING: %s is contraindicated in %ss" % (self.drug, self.species)
elif self.rates[self.species][self.drug] > 0:
return (self.weight * self.rates[self.species][self.drug]) / self.drug_concerntrations[self.drug]
else:
return "Sorry, I'm a stupid computer. Please try again."
"""There are three raw_inputs (speciesQ, weightQ, drugQ) which each have defensive programming to ensure the user input is correct."""
# Loop 1.
# the following while loop is the speciesQ input and defensive programming. Results should be dog, cat, or rabbit.
# strip() removes the whitespace and saves lowercase into speciesQ_stripped.
while True:
speciesQ = raw_input("Enter the species as dog, cat, or rabbit: ")
speciesQ_stripped = speciesQ.lower().strip()
if speciesQ_stripped == "dog" or speciesQ_stripped == "cat" or speciesQ_stripped == "rabbit":
break
# Loop 2.
# the following while loop follows a solution found at http://stackoverflow.com/questions/4138202/python-using-isdigit-for-floats.
# the solution aimed to test for a float and the a number greater than zero and less thank a weight range for each animal.
import re # regular expressions
p = re.compile('\d+(\.\d+)?') # no idea what or how this works
weight_range = {"dog" : 100.0, "cat" : 15.0, "rabbit" : 15.0}
weightQ = raw_input("Enter the weight (kg) of the animal: ")
while True:
weightQ = raw_input("Enter the weight (kg) of the animal: ")
if (p.match(weightQ) != None) and (float(weightQ) > 0) and (float(weightQ) < weight_range[speciesQ_stripped]): # not sure how match works here either
break
# Loop 3.
# the following while loop is similar to the above while loop for speciesQ.
while True:
drugQ = raw_input("Enter the drug type as metacam, synulox, or ketamine: ")
drugQ_stripped = drugQ.lower().lower().strip()
if drugQ_stripped == "metacam" or drugQ_stripped == "synulox" or drugQ_stripped == "ketamine":
break
# Call to the class at the top (Premedicant_dose) utilising the stripped/lowercase version of the user raw_input (the class won't work otherwise)
user_input = Premedicant_dose(speciesQ_stripped, weightQ, drugQ_stripped) #note: stripped
print #blank line
print "Results for premedicant dose of %s for a %s that weighs %s kg: " % (drugQ_stripped, speciesQ_stripped, str(weightQ)) #note: stripped
print #blank line
print str(round(user_input.result())) + "ml" # note: rounded string, prints eg 12.34ml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment