#Bilal Sayed 10/1/17 Project 1

def main():
            
    weight = input_float("What is your weight?(lbs) ")  #gets user input for weight
    while weight < 0:
        print("ERROR: Please enter an positive number:")
        weight = input_float("Enter the correct weight?(lbs) ")
    while weight < 70 or weight > 500:
        print("ERROR: Please enter an valid weight:")
        weight = input_float("Enter the correct weight?(lbs) ")
        
    gender = input_string("What is your gender?(Enter M for male or F for female.) ")   #gets user input for gender
    while gender != 'M' and gender != 'm' and gender != 'F' and gender != 'f':
        print("ERROR: Please enter an valid gender:")
        gender = input_string("Enter the correct gender:(Enter M for male or F for female.) ")
    
    print('')
    print("A standard drink is one 12-ounce beer,\none 5-ounce glass of wine, or one \n1.5-ounce shot of distilled liquor.")    #explains a standard drink
    print('')
    number_of_drinks = input_int("How many standard drinks have you had? ") #gets user input for drinks had
    while number_of_drinks < 0 or number_of_drinks > 15:
        print("ERROR: Please enter a valid number:")
        number_of_drinks = input_int("How many standard drinks have you had? ")
        
    hours = input_int("How long ago did you have your first drink?(Estimate in hours) ")    #gets user input for hours  after
    while hours < 0:
        print("ERROR: Please enter an positive number:")
        hours = input_int("Enter the correct time:(Estimate in hours) ")
    while hours >= 24:
        print("ERROR: Please enter an valid time:")
        hours = input_int("Enter the correct time:(Estimate in hours) ")

    if gender == 'M' or gender == 'm':  #checks to see if gender is male or female
        gender = 0.68
    else:
        gender = 0.55

    blood_alcohol = float(blood_alcohol_content(hours, number_of_drinks, weight, gender)) #calculates the bac
        
    guess = input_float("Try to guess your BAC: ")

    while guess != blood_alcohol:   #allows the user to guess the BAC
        if guess < blood_alcohol:
            print("A little higher. Try again: ")
            guess = input_float("Try to guess your BAC: ")
        elif guess > blood_alcohol:
            print("A little lower. Try again: ")
            guess = input_float("Try to guess your BAC: ")
        else:
            break

    print('')
    
    if guess == blood_alcohol:  #prints a message when the user guesses the correc BAC
        print("---------")
        print("|Correct!|")
        print("---------")
        
    print('')    
    print("Your Blood Alchohol Content is ", blood_alcohol, "%")

    while blood_alcohol >= .08: #Prints a message if user is over the legal limit
        print("You are over the legal BAC limit for driving.")
        break
              
    print('')
    bac_effects(blood_alcohol)  #prints the effect of the user BAC
            
    if gender == 0.68:  #sets m to male and f to female for the print output
        gender = 'Male'
    else:
        gender = 'Female'

    print('')
    print("You entered", weight, "lbs as your weight")  #prints weight
    print("You entered", gender, "as your gender")  #prints gender
    print("You entered", number_of_drinks, "as the number of drinks you had")   #prints drinks
    print("You entered", hours, "as the number of hours since your first drink")    #prints hours after first drink
    print('')
    
    graph(blood_alcohol)

    print('Check the other Python window for a graph')

def blood_alcohol_content(a, b, c, d):  #BAC equation function
    result = format(float(-0.015 * a + ((2.48 * b) / (c * d))),',.2f')
    return result
    
def input_int(message): #user input validation to check if input is a int
  while True:           #i found this method online when I coulnt get my method to work
    try:                #which was using type to compare the user input to a constant integer 
       userInput = int(input(message))       
    except ValueError:
       print("ERROR: Not an valid input. Please enter a number.")
       continue
    else:
       return userInput 
       break
    
def input_float(message):   #user input validation to check if input is a float
  while True:
    try:
       userInput = float(input(message))       
    except ValueError:
       print("ERROR: Not an valid input. Please enter a number.")
       continue
    else:
       return userInput 
       break

def input_string(message): #user input validation to check if input is a string
  while True:
    try:
       userInput = str(input(message))       
    except ValueError:
       print("ERROR: Not an valid input. You can only enter character in this field.")
       continue
    else:
       return userInput 
       break

def bac_effects(a): #function for the BAC effects
    if a < 0.03:
        effect = "Normal behavior, no impairment."
    elif a >= .03 and a < .06:
        effect = "Mild euphoria and impairment."
    elif a >= .06 and a < .10:
        effect = "Euphoric, increased impairment."
    elif a >= .10 and a < .20:
        effect = "Drunk, loss of motor control."
    elif a >= .20 and a < .30:
        effect = "Confused, possible blackout."
    elif a >= .30 and a < .40:
        effect = "Possibly unconscious."
    else:
        effect = "Unconscious, risk of death."
    print("The effect will be", effect)

def graph(blood_alcohol):   #this function graphs the user input
    import turtle
    turtle.hideturtle()
    turtle.speed(0)
    turtle.setup(1920, 1080)
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.penup()
    turtle.goto(-850, -370)
    turtle.pendown()
    turtle.setheading(0)
    turtle.forward(1600)
    turtle.setheading(160)
    turtle.forward(15)
    turtle.penup()
    turtle.setheading(340)
    turtle.forward(15)
    turtle.setheading(200)
    turtle.pendown()
    turtle.forward(15)
    turtle.penup()
    turtle.goto(-850, -370)
    turtle.pendown()
    turtle.setheading(90)
    turtle.forward(850)
    turtle.setheading(250)
    turtle.forward(15)
    turtle.penup()
    turtle.setheading(70)
    turtle.forward(15)
    turtle.setheading(290)
    turtle.pendown()
    turtle.forward(15)
    turtle.penup()
    turtle.goto(-850, -370)
    for num in range(8):
        turtle.pendown()
        turtle.setheading(90)
        turtle.forward(10)
        turtle.setheading(270)
        turtle.forward(20)
        turtle.penup()
        turtle.setheading(90)
        turtle.forward(10)
        turtle.setheading(0)
        turtle.forward(200)
    turtle.goto(-850, -370)
    for num in range(21):
        turtle.pendown()
        turtle.setheading(0)
        turtle.forward(10)
        turtle.setheading(180)
        turtle.forward(20)
        turtle.penup()
        turtle.setheading(0)
        turtle.forward(10)
        turtle.setheading(90)
        turtle.forward(40)
    turtle.goto(-850, -370)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.pendown()
    turtle.goto(-650, -310)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.pendown()
    turtle.goto(-450, -250)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.goto(-250, -170)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.goto(-50, 30)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.goto(150, 230)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.goto(350, 430)
    turtle.pensize(5)
    turtle.pencolor('blue')
    turtle.dot()
    turtle.pensize(1)
    turtle.pencolor('black')
    turtle.penup()
    turtle.goto(-900, -380)
    turtle.write('0.0')
    turtle.goto(-900, -340)
    turtle.write('0.02')
    turtle.goto(-900, -300)
    turtle.write('0.04')
    turtle.goto(-900, -260)
    turtle.write('0.06')
    turtle.goto(-900, -220)
    turtle.write('0.08')
    turtle.goto(-900, -180)
    turtle.write('0.10')
    turtle.goto(-900, -140)
    turtle.write('0.12')
    turtle.goto(-900, -100)
    turtle.write('0.14')
    turtle.goto(-900, -60)
    turtle.write('0.16')
    turtle.goto(-900, -20)
    turtle.write('0.18')
    turtle.goto(-900, 20)
    turtle.write('0.20')
    turtle.goto(-900, 60)
    turtle.write('0.22')
    turtle.goto(-900, 100)
    turtle.write('0.24')
    turtle.goto(-900, 140)
    turtle.write('0.26')
    turtle.goto(-900, 180)
    turtle.write('0.28')
    turtle.goto(-900, 220)
    turtle.write('0.30')
    turtle.goto(-900, 260)
    turtle.write('0.32')
    turtle.goto(-900, 300)
    turtle.write('0.34')
    turtle.goto(-900, 340)
    turtle.write('0.36')
    turtle.goto(-900, 380)
    turtle.write('0.38')
    turtle.goto(-900, 420)
    turtle.write('0.40')
    turtle.goto(-950, 480)
    turtle.write('Blood Alcohol Content')
    turtle.write('Blood Alcohol Content')
    turtle.goto(-810, -420)
    turtle.write('Normal behavior, no impairment')
    turtle.goto(-610, -420)
    turtle.write('Mild euphoria and impairment')
    turtle.goto(-410, -420)
    turtle.write('Euphoric, increased impairment')
    turtle.goto(-210, -420)
    turtle.write('Drunk, loss of motor control')
    turtle.goto(-10, -420)
    turtle.write('Confused, possible blackout')
    turtle.goto(190, -420)
    turtle.write('Possibly unconscious')
    turtle.goto(390, -420)
    turtle.write('Unconscious, risk of death')
    turtle.goto(-70, -460)
    turtle.write('BAC Effect')
    turtle.write('BAC Effect')
    turtle.penup()
    if blood_alcohol == .01:
        turtle.goto(-784, -350)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .01%')
    elif blood_alcohol == .02:
        turtle.goto(-718, -330)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .02%')
    elif blood_alcohol == .03:
        turtle.goto(-650, -310)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .03%')
    elif blood_alcohol == .04:
        turtle.goto(-586, -290)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .04%')
    elif blood_alcohol == .05:
        turtle.goto(-520, -270)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .05%')
    elif blood_alcohol == .06:
        turtle.goto(-450, -250)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .06%')
    elif blood_alcohol == .07:
        turtle.goto(-400, -230)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .07%')
    elif blood_alcohol == .08:
        turtle.goto(-350, -210)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .08%')
    elif blood_alcohol == .09:
        turtle.goto(-300, -190)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .09%')
    elif blood_alcohol == .10:
        turtle.goto(-250, -170)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .10%')
    elif blood_alcohol == .11:
        turtle.goto(-230, -150)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .11%')
    elif blood_alcohol == .12:
        turtle.goto(-210, -130)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .12%')
    elif blood_alcohol == .13:
        turtle.goto(-190, -110)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .13%')
    elif blood_alcohol == .14:
        turtle.goto(-170, -90)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .14%') 
    elif blood_alcohol == .15:
        turtle.goto(-150, -70)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .15%') 
    elif blood_alcohol == .16:
        turtle.goto(-130, -50)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .16%') 
    elif blood_alcohol == .17:
        turtle.goto(-110, -30)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .17%')
    elif blood_alcohol == .18:
        turtle.goto(-90, -10)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .18%')
    elif blood_alcohol == .19:
        turtle.goto(-70, 10)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .19%')
    elif blood_alcohol == .20:
        turtle.goto(-50, 30)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .20%')
    elif blood_alcohol == .21:
        turtle.goto(-30, 50)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .21%')
    elif blood_alcohol == .22:
        turtle.goto(-10, 70)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .22%')
    elif blood_alcohol == .23:
        turtle.goto(10, 90)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .23%')
    elif blood_alcohol == .24:
        turtle.goto(30, 110)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .24%')
    elif blood_alcohol == .25:
        turtle.goto(50, 130)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .25%')
    elif blood_alcohol == .26:
        turtle.goto(70, 150)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .26%')
    elif blood_alcohol == .27:
        turtle.goto(90, 170)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .27%')
    elif blood_alcohol == .28:
        turtle.goto(110, 190)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .28%')
    elif blood_alcohol == .29:
        turtle.goto(130, 210)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .29%')
    elif blood_alcohol == .30:
        turtle.goto(150, 230)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .30%')
    elif blood_alcohol == .31:
        turtle.goto(170, 250)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .31%')
    elif blood_alcohol == .32:
        turtle.goto(190, 270)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .32%')
    elif blood_alcohol == .33:
        turtle.goto(210, 290)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .33%')
    elif blood_alcohol == .34:
        turtle.goto(230, 310)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .34%')
    elif blood_alcohol == .35:
        turtle.goto(250, 330)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .35%')
    elif blood_alcohol == .36:
        turtle.goto(270, 350)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .36%')
    elif blood_alcohol == .37:
        turtle.goto(290, 370)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .37%')
    elif blood_alcohol == .38:
        turtle.goto(410, 390)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .38%')
    elif blood_alcohol == .39:
        turtle.goto(430, 410)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .39%')
    elif blood_alcohol == .40:
        turtle.goto(450, 430)
        turtle.pencolor('red')
        turtle.pensize(5)
        turtle.dot()
        turtle.penup()
        turtle.setheading(270)
        turtle.forward(15)
        turtle.setheading(0)
        turtle.forward(5)
        turtle.write('Your BAC is .40%')
    else:
        print("ERROR!")
    turtle.penup()
    

main()
