Im trying to make a bac calculator and make a gui for it but am having issues with the math code for it.

Here's my code. Everything I input returns 0.

The BAC forumula is (150/body weight)(% alcohol/50)(ounces consumed)(0.025). Btw, I suck at math so it could be a math error....

class main():
	def bac(self):
		drink=raw_input("What kind of drink was it? 12oz. ([B]eer, 5oz. [W]ine, 1.25oz. [S]hot) ")
		if drink=="b":
			weight=raw_input("What is your Body weight in pounds? ")
			w=150.0/int(weight) #body weight
			q=.04/50 #beer alcohol content
			z=raw_input("How many drink were consumed? ") #consumed ounces
			x=0.025 
			bac=int(w)*int(q)*int(z)*int(x)
			print bac

The problem is all those int casts: casting a fraction between 0 and 1 to int results in a zero. Here's a slightly modified program that makes that change as well as hoisting some of the code out of the 'beer' block. I really don't understand what all the arithmetic is about, so I left it alone.

Note that creating a class for this exercise is considerable overkill for the task at hand. I left it there, to make the difference a little more clear

class main():
  def bac(self):
    weight=raw_input("What is your Body weight in pounds? ")
    drink=raw_input("What kind of drink was it? 12oz. ([B]eer, 5oz. [W]ine, 1.25oz. [S]hot) ")
    w=150.0/float(weight) #body weight
    print 'w is %f'%w
    if drink=="b" or drink == 'w':
      q=.04/50 #beer or wine alcohol content
    else:
      q = .12/50 # imaginary shot
    z=raw_input("How many drink were consumed? ")
    x=0.025
    bac=float(w)*float(q)*float(z)*x
    print bac

m = main()
m.bac()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.