input: Write a function to set up GPIO pins, import necessary modules, prompt for password and mode selection, check license validity and user registration, calculate BAC, open solenoid to dispense beer if valid license and BAC below threshold, and record swipe data in appropriate file.
  
  
  # Setting up GPIO pins
  from time import sleep
  import RPi.GPIO as GPIO
  
  GPIO.setmode(GPIO.BOARD) # Identifies the pin numbers to the pi
  GPIO.setwarnings(False)
  
  GPIO.setup(3, GPIO.OUT) # Should sets pin #3 as an output...but doesnt work yet
  GPIO.setup(3, GPIO.LOW) # Turns initial output for pin 3 off
  
  import time
  timestr = time.strftime("%Y%m%d %H%M%S")
  
  # Import functions to analyze license validity from CheckLicense.py
  from CheckLicense import check_license, calc_BAC
  
                                   
  import getpass
  import sys
  import re
  
  def dispense_beer():
      # Operating modes
      mode = None
      while True:
          mode_req = input("Enter Mode(normal, party, barkeep): ")
          
          if mode_req == "party":
              passwd = getpass.getpass("Enter password: ")
              if passwd == "admin":
                  mode = "party"
          
          if mode_req == "normal":
              passwd = getpass.getpass("Enter password: ")
              if passwd == "admin":
                  mode = "normal"
          
          if mode_req == "barkeep":
              passwd = getpass.getpass("Enter password: ")
              if passwd == "admin":
                  mode = "barkeep"
          
          if mode:
              break
      
      while mode == 'normal':
          print(f'{mode} mode!')
          
          raw_text = getpass.getpass('Swipe card now:   ').strip() 
          check_license_out = check_license(raw_text)
          
          valid_license = check_license_out[0] 
          first_name = check_license_out[1]
          last_name = check_license_out[2]
          DL_num = check_license_out[3]
          
          users = open("users_list.txt", 'r')
          hit = 0
          
          if valid_license == 'Yes':
              for line in users:
                  if re.search(DL_num, line, re.IGNORECASE):
                      hit += 1
              if hit >= 1:
                  valid_license = 'Yes'
              else: 
                  print('Not registered user')
                  valid_license = 'No'
          
          BAC = calc_BAC(raw_text)
          print(BAC)
          
          if valid_license == 'Yes':
              GPIO.setup(3, GPIO.HIGH)
              print('Beer time!')
              sleep(2)
              GPIO.setup(3, GPIO.LOW)
              with open("swipes.txt", "a") as myfile:
                  myfile.write(f"{last_name},{first_name} ")
                  myfile.write(f"{DL_num} ")
                  myfile.write(f"{mode} ")
                  myfile.write(f"{time.strftime('%Y-%m-%d')} ")
                  myfile.write(f"{str(time.time())}\n")
                  
      while mode == "party":
          print(f'{mode} mode!')
          raw_license_text = getpass.getpass('Swipe card now:   ').strip()
          check_license_out = check_license(raw_license_text) 
          
          valid_license = check_license_out[0] 
          first_name = check_license_out[1]
          last_name = check_license_out[2] 
          
          if valid_license == 'Yes':
              GPIO.setup(3, GPIO.HIGH)
              print('Beer time!')
              sleep(2)
              GPIO.setup(3, GPIO.LOW)
              with open("swipes_normal.txt", "a") as myfile:
                  myfile.write(f"{last_name},{first_name},{time.strftime('%Y%m%d%H%M%S\n')}")
                  
      while mode == "barkeep":
          print(f'{mode} mode!')
          check_license_out = check_license(getpass.getpass('Swipe card now:   ').strip()) 
          
          valid_license = check_license_out[0] 
          first_name = check_license_out[1]
          last_name = check_license_out[2] 
          
          blacklist = open("blacklist.txt", 'r')
          hit = 0
          
          if valid_license == 'Yes':
              for line in blacklist:
                  if re.search(last_name, line, re.IGNORECASE):
                      hit += 1
                  if re.search(first_name, line, re.IGNORECASE):
                      hit += 1
              if hit >= 2:
                  print("We don't serve your kind here.")
                  blacklisted = 'Yes'
              else: 
                  blacklisted = 'No'
          
          BAC = calc_BAC(raw_text)
          
          if blacklisted == 'No' and BAC < intoxicated:
              GPIO.setup(3, GPIO.HIGH)
              print('Beer time!')
              print(BAC)
              sleep(2)
              GPIO.setup(3, GPIO.LOW)
              with open("swipes_barkeep.txt", "a") as myfile:
                  myfile.write(f"{last_name},{first_name}_{time.strftime('%Y-%m-%d %H:%M%S\n')}")
          else:
              print(f'Your BAC is {BAC}')
              print("You are too drunk, beer time is over")
              
  dispense_beer()
  
  
  assert dispense_beer() == "Beer time!"
  assert dispense_beer() == "Not registered user"
  assert dispense_beer() == "We don't serve your kind here."
  assert dispense_beer() == "You are too drunk, beer time is over"
output: def dispense_beer():
      mode = None
      while True:
          mode_req = input("Enter Mode(normal, party, barkeep): ")
          
          if mode_req == "party":
              passwd = getpass.getpass("Enter password: ")
              if passwd == "admin":
                  mode = "party"
          
          if mode_req == "normal":
              passwd = getpass.getpass("Enter password: ")
              if passwd == "admin":
                  mode = "normal"
          
          if mode_req == "barkeep":
              passwd = getpass.getpass("Enter password: ")
              if passwd == "admin":
                  mode = "barkeep"
          
          if mode:
              break
      
      while mode == 'normal':
          print(f'{mode} mode!')
          
          raw_text = getpass.getpass('Swipe card now:   ').strip() 
          check_license_out = check_license(raw_text)
          
          valid_license = check_license_out[0] 
          first_name = check_license_out[1]
          last_name = check_license_out[2]
          DL_num = check_license_out[3]
          
          users = open("users_list.txt", 'r')
          hit = 0
          
          if valid_license == 'Yes':
              for line in users:
                  if re.search(DL_num, line, re.IGNORECASE):
                      hit += 1
              if hit >= 1:
                  valid_license = 'Yes'
              else: 
                  print('Not registered user')
                  valid_license = 'No'
          
          BAC = calc_BAC(raw_text)
          print(BAC)
          
          if valid_license == 'Yes':
              GPIO.setup(3, GPIO.HIGH)
              print('Beer time!')
              sleep(2)
              GPIO.setup(3, GPIO.LOW)
              with open("swipes.txt", "a") as myfile:
                  myfile.write(f"{last_name},{first_name} ")
                  myfile.write(f"{DL_num} ")
                  myfile.write(f"{mode} ")
                  myfile.write(f"{time.strftime('%Y-%m-%d')} ")
                  myfile.write(f"{str(time.time())}\n")
                  
      while mode == "party":
          print(f'{mode} mode!')
          raw_license_text = getpass.getpass('Swipe card now:   ').strip()
          check_license_out = check_license(raw_license_text) 
          
          valid_license = check_license_out[0] 
          first_name = check_license_out[1]
          last_name = check_license_out[2] 
          
          if valid_license == 'Yes':
              GPIO.setup(3, GPIO.HIGH)
              print('Beer time!')
              sleep(2)
              GPIO.setup(3, GPIO.LOW)
              with open("swipes_normal.txt", "a") as myfile:
                  myfile.write(f"{last_name},{first_name},{time.strftime('%Y%m%d%H%M%S\n')}")
                  
      while mode == "barkeep":
          print(f'{mode} mode!')
          check_license_out = check_license(getpass.getpass('Swipe card now:   ').strip()) 
          
          valid_license = check_license_out[0] 
          first_name = check_license_out[1]
          last_name = check_license_out[2] 
          
          blacklist = open("blacklist.txt", 'r')
          hit = 0
          
          if valid_license == 'Yes':
              for line in blacklist:
                  if re.search(last_name, line, re.IGNORECASE):
                      hit += 1
                  if re.search(first_name, line, re.IGNORECASE):
                      hit += 1
              if hit >= 2:
                  print("We don't serve your kind here.")
                  blacklisted = 'Yes'
              else: 
                  blacklisted = 'No'
          
          BAC = calc_BAC(raw_text)
          
          if blacklisted == 'No' and BAC < intoxicated:
              GPIO.setup(3, GPIO.HIGH)
              print('Beer time!')
              print(BAC)
              sleep(2)
              GPIO.setup(3, GPIO.LOW)
              with open("swipes_barkeep.txt", "a") as myfile:
                  myfile.write(f"{last_name},{first_name}_{time.strftime('%Y-%m-%d %H:%M%S\n')}")
          else:
              print(f'Your BAC is {BAC}')
              print("You are too drunk, beer time is over")