text: 
                                                                              #importing modules
  import math
  import random
  import os
  import pickle
  import time
  import PIL
  import webbrowser
  import subprocess
  from os import walk
  from PIL import Image
                                                                              #lists of inputs and outputs
  hai=['HI','HAI','HELLO','HALLO','HALO','HEY','HY']
  hi=['hi','hai','hey','hello','halo','hy','hallo','Hi','Hai','Hey','Hello','Halo','Hy','Hallo']
  quit=['QUIT','EXIT','END']
  bi=['BI','BY','BAI','BYE']
  bye=['I will wait for you','Bye see you Soon','Oh that hurts me','Did I made a mistake']
  yes=['YES','YEA','YEAH','YA','SURE','OF COURSE']
  wru=['WHO ARE YOU','?','W R U','WHO R U','WHO ARE YOU?','WHO R U?','WHO ARE U','WHO ARE U?']
  AI=['Just call me Buddy', 'Call me Buddy', 'I am  your personal assistant, Buddy!!'
      ,'Buddy At your service','I am buddy\n\t What can I do for You?']
  sav=['SAVE','REMEMBER','MEMO','NOTE']
  typ=['Say what do you want to ramemember?', 'What do yo want me to remember?'
       , 'What should I want to save?']
  done=['I have done that for you','Done!!','I\'ll remember that','All Done']
  pic=['PIC','PICTURES','PICTURE','IMAGE','IMAGES','PICS']
  note=['MY NOTES','SEARCH','NOTES','FIND']
  no=['NO','NOPE','NOPS','NEVER']
  pi=['PI']
  siri=['SIRI']
  siri_error=['I think You have misspelled','Hey...\n\t Wait... Iam not Siri','Siri is nice...but I am Buddy','Call me buddy okay!!',
              'I dont think you have an iphone\n\t Do you??','siri_web','Siri is my buddy , I am Buddy!!']
  cortana=['CORTANA']
  cortana_error=['I think You have misspelled','Hey...\n\t Wait... Iam not Cortana','Cortana is nice...but I am Buddy','Call me buddy okay!!',
              'I dont think you have a Windows phone\n\t Do you??','cortana_web','Cortana is my buddy , I am Buddy!!']
  allo=['ALLO']
  allo_error=['I think You have misspelled','Hey...\n\t Wait... Iam not Allo','Allo is nice...but I am Buddy','Call me buddy okay!!',
              'I dont think you have a Pixel\n\t Do you??','allo_web','Allo is my buddy , I am Buddy!!']
  pswd_error=['I will not say','Password','Sorry how can I verify you are authorized!!',
              'It is *****.....or may be *******......or sometimes ******* ','I dont Know!!',
              'Dont play with me then how did you signed in']
  cal=['CALCULATOR','CALCULATE']
  game=['GAME','PLAY','GAMES']
  hru=['HOW ARE YOU','HOW R U','HOW ARE U','HW R U','HOW ARE YOU?','HOW R U?','HOW ARE U?','HW R U?',
       'HOW ARE YOU BUDDY','HOW R U BUDDY','HOW ARE U BUDDY','HW R U BUDDY','HOW ARE YOU BUDDY?','HOW R U BUDDY?','HOW ARE U BUDDY?','HW R U BUDDY?',
       'BUDDY HOW ARE YOU','BUDDY HOW R U','BUDDY HOW ARE U','BUDDY HW R U','BUDDY HOW ARE YOU?','BUDDY HOW R U?','BUDDY HOW ARE U?','BUDDY HW R U?',]
  fine=['fine','i am fine','nice','going well','well','Fine','I am fine','Nice','Going well','Well',
        'Fine !','I am fine thank you','Nice !','Going well !','well !']
  delete=['DELETE','REMOVE','DEL']
  time_=['TIME','CLOCK']
  doubt=['DOUBT','QUESTION','Q&A']
  ycod=['WHO CREATED YOU','WHO IS YOUR FATHER','WHO IS YOUR MOTHER','WHO DEVELOPED YOU','DEVELOPERS',
        'WHO CREATED YOU?','WHO IS YOUR FATHER?','WHO IS YOUR MOTHER?','WHO DEVELOPED YOU?']
  fb=['FB','FACEBOOK','FACE BOOK']
  quora=['QUORA']
  pass_word=['PASSWORD','PSWD','PASSWD','PSSWD','PSWORD','PSSWORD']
  print '\t\t\t\t\t BUDDY'
  name=raw_input("Buddy:   Hai What is your name? \n")                        #creates a folder with the user name
  NAME=name.upper()
  q= os.getcwd()+"\\"
  path=q+NAME
  if not os.path.exists(path):
      os.makedirs(path)
  os.chdir(path)
  global np
  global game_n0
  global x
  np=os.getcwd()
  pswd=raw_input("Buddy:   Your Password \n")                                 #sets password or checks the password
  try:
      p1=open('.pswd','r+')
      password=str(p1.read())
  except IOError:
      f=open('.pswd','w+')
      f.write(pswd)
      f.close()
  p1=open('.pswd','r+')
  password=str(p1.read())    
  if pswd==password:
      print '\t\t\t\tWelcome',name
  else:
      print 'Wrong Password!!' 
      exit()
  p1.close()
  def filenames(f,mypath):                                                    #function to open files 
      for (dirpath, dirnames, filenames) in walk(mypath):
          f.extend(filenames)
          break
      return f
  def imo(f):                                                                 #function to open images
      im = Image.open(f+".jpg")
      im.show()
  def clock():                                                                #function to show time
          _24hrtim=time.localtime()
          _24hr=_24hrtim[3]
          _24min=_24hrtim[4]
          _24sec=_24hrtim[5]
          if 0<int(_24hr)<12:
              return ("Buddy:   The time is "+str(_24hr)+':'+str(_24min)+':'+str(_24sec)+' AM'+'\n\t '+str(_24hrtim[2])+'/'+str(_24hrtim[1])+'/'+str(_24hrtim[0]))
          elif int(_24hr)==12:
              return ("Buddy:   The time is "+str(_24hr)+':'+str(_24min)+':'+str(_24sec)+' PM'+'\n\t '+str(_24hrtim[2])+'/'+str(_24hrtim[1])+'/'+str(_24hrtim[0]))
          elif _24hr==0:
              return ("Buddy:   The time is "+str(12)+':'+str(_24min)+':'+str(_24sec)+' AM'+'\n\t '+str(_24hrtim[2])+'/'+str(_24hrtim[1])+'/'+str(_24hrtim[0]))
          else:
              return ("Buddy:   The time is "+str(int(_24hr)-12)+':'+str(_24min)+':'+str(_24sec)+' PM'+'\n\t '+str(_24hrtim[2])+'/'+str(_24hrtim[1])+'/'+str(_24hrtim[0]))
  while True:                                                                 #Loops continuously
      x=raw_input(name+':    ')                                               #takes your input
      y=x.upper()
      p=y.split(' ')
      if len(set(p).intersection(set(quit)))!=0:                              #responds to your exit
          print "Buddy:   Good bye see you soon"
          break
      elif p[0]=='G':                                                         #searches for you in google
          gs1=y.replace('G ','',1)
          gs1=gs1.lower()
          gs2=gs1.replace(' ','+')
          new=2
          url = "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q="+gs2
          webbrowser.open(url,new=new)
      elif y in hru:                                                          #responds to How are you
          print "Buddy:  ",fine[random.randint(0,len(fine)-1)]
      elif len(set(p).intersection(set(siri)))!=0:                            #responds if called siri by mistake
          siri_error1=siri_error[random.randint(0,len(siri_error)-1)]
          if siri_error1=='siri_web':
              new=2
              url = "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=Siri"
              webbrowser.open(url,new=new)
          else:
              print "Buddy:  ",siri_error1
      elif len(set(p).intersection(set(cortana)))!=0:                         #responds if called cortana by mistake
          cortana_error1=cortana_error[random.randint(0,len(cortana_error)-1)]
          if cortana_error1=='cortana_web':
              new=2
              url = "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=Cortana"
              webbrowser.open(url,new=new)
          else:
              print "Buddy:  ",cortana_error1
      elif len(set(p).intersection(set(allo)))!=0:                            #responds if called allo by mistake
          allo_error1=allo_error[random.randint(0,len(allo_error)-1)]
          if allo_error1=='allo_web':
              new=2
              url = "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=Allo+Google+Assistant"
              webbrowser.open(url,new=new)
          else:
              print "Buddy:  ",allo_error1        
      elif y=='BUDDY':                                                        #responds to your call Buddy
          print'Buddy:   Yessss Buddy hear...'
      elif len(set(p).intersection(set(delete)))!=0:                          #helps to delete your files
          delfile=y.replace(p[0]+' ','')
          delfile1=delfile.lower()
          print "Buddy:   Are you sure you want to delete",delfile1
          delfile_con=raw_input(name+':    ')
          try:
              if delfile_con.upper() in yes:
                  os.remove(delfile1)
          except:
              print "Buddy:   No such file found!!"        
      elif y in wru:                                                          #responds to the question who are you
          print "Buddy:  ",AI[random.randint(0,len(AI)-1)]
      elif len(set(p).intersection(set(sav)))!=0:                             #helps to save your notes
          print "Buddy:  ",typ[random.randint(0,len(typ)-1)],'\n\t Tell me the title'
          title=raw_input(name+':    ')
          print "Buddy:   Now please Type the content"
          content=raw_input(name+':    ')
          try:
              note_open=open(title,'w+')
              note_open.write('\t\t\t'+title+'\n'+'\t '+content+'\n\n\n\t at '+(clock().split(' '))[6]+' '+(clock().split(' '))[7]+' '+(clock().split(' '))[8])
              note_open.close()
              print "Buddy:  ",done[random.randint(0,len(done)-1)]
          except:
              print "Buddy:   You have typed an invalid file name!!"
      elif len(set(p).intersection(set(pic)))!=0:                             #helps to show your pics
          try:
              print "Buddy:   Tell me what picture You want to see"
              picname=raw_input(name+':    ')
              imo(picname)
          except:
              temp_list=[]
              filenames(temp_list,np)
              print "Buddy:   These are the file you have"
              for i in range (0,len(temp_list)-1):
                  print ' ',temp_list[i],
              print
      elif len(set(p).intersection(set(note)))!=0:                            #displays your saved notes 
          try:
              print "Buddy:   Please tell me the title of the note"
              title_s=raw_input(name+':    ')
              fo_note=open(title_s,'r+')
              print fo_note.read()
          except:
              temp_list=[]
              filenames(temp_list,np)
              print "Buddy:   These are the file you have"
              for i in range (0,len(temp_list)-1):
                  print ' ',temp_list[i],
              print
      elif len(set(p).intersection(set(pi)))!=0:                              #shows the value of pi
          print "Buddy:   The value of Pi is 3.141592653589793238462643383279502884197169399375105820974944592307816406286"
      elif len(set(p).intersection(set(cal)))!=0:                             #launches numpad calculator inbuilt app
          print('\t\t\t\t Please select calculator mode \n\t\t\t\t "0" for the standard calculator \n\t\t\t\t "1" to find unit vector in the direction of agiven vector \
                \n\t\t\t\t "2" to find dot product of 2 vectors \n\t\t\t\t "3" to find cross product of 2 vectors\
                \n\t\t\t\t "4" to find solution of quadratic equation\n\t\t\t\t "5" to do trigonometry\n\t\t\t\t "6" to quit')
          while True:
              a1=raw_input('Select Mode: ')
              if (a1=='1'):                                                   #unit vector calculator
                  try:
                      x1=float(input('x=  '))
                      y1=float(input('y=  '))
                      z1=float(input('z=  '))
                      p1=(((x1**2)+(y1**2)+(z1**2))**(.5))
                      if p1!=0:
                          print 'Unit vector in the direction of given vector is ',(x1/p1),'i + ',(y1/p1),'j + ',(z1/p1),'k'
                      else:
                          print'You entered a null Vector!!'
                  except:
                      print 'You have entered a wrong input!!'
              elif (a1=='4'):                                                 #solution for quadratic equations
                  print 'Enter the values of a, b, c where a b c are ax^2+bx+c'
                  try:
                      _a=input('a= ')
                      _b=input('b= ')
                      _c=input('c= ')
                      _d=_b**2-4*_a*_c
                      if _d<0:
                          print 'The roots are imaginary'
                      else:
                          _e=_d**.5
                          root1=((-_b)+_e)/(2*_a)
                          root2=((-_b)-_e)/(2*_a)
                          print 'The roots are',root1,'and',root2
                  except:
                      print 'You have entered a wrong input'
              elif (a1=='5'):                                                 #trigonometric calculator
                  trigo_input=raw_input('Enter 1 for sin, 2 for cos, 3 for tan: ')
                  try:
                      trigo_value=input('Enter the value of x in degrees: ')
                      trigo_value1=math.radians(trigo_value)
                      if trigo_input=='1':
                          print math.sin(trigo_value1)
                      elif trigo_input=='2':
                          if trigo_value==90:
                              print 1
                          else:
                              math.cos(trigo_value1)
                      elif trigo_input=='3':
                          if trigo_value==90:
                              print 'Not defined'
                          else:    
                              print math.tan(trigo_value1)
                      else:
                          print 'Please enter a valid input!!'
                  except:
                      print 'Please enter a valid input!!'
              elif (a1=='0'):                                                 #simple calculator
                  try:
                      t1=float(input('Your first number: '))
                      u1=raw_input('Enter the operator:   ' )
                      v1=float(input('Your second number: '))
                      if (u1=='+'):
                          print float(t1+v1)
                      elif (u1=='-'):
                          print float(t1-v1)
                      elif (u1=='*'):
                          print float(t1*v1)
                      elif (u1=='/'):
                          if (v1==0):
                              print 'Any number divided by zero is not defined'
                          else:
                              print float(t1/v1)
                      elif (u1=='%'):
                          print'The Remainder is  ',float(t1%v1)
                      elif (u1=='//'):
                         print float(t1//v1)
                      elif (u1=='^'):
                          print float(t1**v1)
                  except:
                      print '\tYou entered a letter!!' 
              elif (a1== '2'):                                                #dot product calculator
                  try:
                      x_1=float(input('x1=  '))
                      y_1=float(input('y1=  '))
                      z_1=float(input('z1=  '))
                      x_2=float(input('x2=  '))
                      y_2=float(input('y2=  '))
                      z_2=float(input('z2=  '))
                      print (x_1*x_2)+(y_1*y_2)+(z_1*z_2)
                  except:
                      print '\tYou entered a letter!!'
              elif (a1== '3'):                                                #cross product calculator
                  try:
                      x__1=float(input('x1=  '))
                      y__1=float(input('y1=  '))
                      z__1=float(input('z1=  '))
                      x__2=float(input('x2=  '))
                      y__2=float(input('y2=  '))
                      z__2=float(input('z2=  '))
                      print ((y__1*z__2)-(z__1*y__2)),'i + ',-((x__1*z__2)-(z__1*x__2)),'j + ',((x__1*y__2)-(y__1*x__2)),'k'
                  except:
                      print '\tYou entered a letter!!'
              elif a1=='6':                                                   #exits calculator
                  break
              else:
                  print 'Please select a mode'
      elif len(set(p).intersection(set(game)))!=0:                            #launches games available in your folder if not present downloads it for you
          try:
              print "Buddy:   Which game do you want?"
              game_n=raw_input(name+':    ')
              game_n0=game_n.replace(' ','+')
              game_n1=game_n.upper()
              g_path=path+'\\'+game_n1
              os.chdir(g_path)
              g_file=g_path+'\\Chuzzle.exe'
              subprocess.Popen(g_file)
              os.chdir(np)
          except:
              try:
                  print "Buddy:   Sorry ",name,' I did not find that game \n\t Do you want to download the game?'
                  game_dwnld=raw_input(name+':    ')
                  game_dwnld1=game_dwnld.upper()
                  game_dwnld2=game_dwnld1.split(' ')
                  if len(set(game_dwnld2).intersection(set(yes)))!=0:
                      new=2
                      url = "https://www.google.co.in/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q="+'free+download+'+game_n0
                      webbrowser.open(url,new=new)
                  elif game_dwnld1 in no:
                      print "Buddy:   Please enter the folder name of the game"
                      game_folder_name=raw_input(name+':    ')
                      print "Buddy:   Please enter the name of the game file without .exe "
                      game_name=raw_input(name+':    ')
                      ng_path=path+'\\'+game_folder_name
                      os.chdir(ng_path)
                      ng_file=ng_path+'\\'+game_name+'.exe'
                      subprocess.Popen(ng_file)
                      os.chdir(np)
              except :
                  print "Buddy:   Sorry ",name,' I dont have such a game'
      elif len(set(p).intersection(set(fb)))!=0:
          new=2
          url = "https://www.facebook.com/"
          webbrowser.open(url,new=new)
      elif len(set(p).intersection(set(quora)))!=0:
          new=2
          url = "https://www.quora.com/"
          webbrowser.open(url,new=new)
      elif len(set(p).intersection(set(time_)))!=0:                           # displays time in 12 hr format
          print clock() 
      elif len(set(p).intersection(set(hai)))!=0:                             #responds to your hai
          print "Buddy:  ",hi[random.randint(0,len(hi)-1)],name
      elif len(set(p).intersection(set(pass_word)))!=0:                       #responds if the user asks for the password
           print "Buddy:  ",pswd_error[random.randint(0,len(pswd_error)-1)]
      elif len(set(p).intersection(set(bi)))!=0:                              #responds to your bye
          print "Buddy:   Are You Sure you want to quit"
          if raw_input(name+':    ').upper() in yes:
               print "Buddy:  ",bye[random.randint(0,len(bye)-1)]
               break
          else:
               print "Buddy:   Thanks for continuing"
      elif y in ycod:
          print "Buddy:   Stay in your limits bud"                            #names of group members
      else:                                                                   #if Buddy doesnt understands you, It learns from you
          try:                                                                #this learning is exclusive for user
              tfor=open('teach_b','r')
              tfordict=pickle.load(tfor)
              tf_p=tfordict[x]
              print 'Buddy:  ',tf_p
              tfor.close()
          except:
              print 'Buddy:   Sorry I dont get You\n\t Would you like to teach me?'
              teach_y_n=raw_input(name+':    ')
              if teach_y_n.upper() in yes:
                  tfor=open('teach_b','w')
                  print 'Buddy:   What should I reply?'
                  qout=raw_input(name+':    ')
                  try:
                      tfordict[x]=qout
                  except:
                      tfordict={}
                      tfordict[x]=qout
                  pickle.dump(tfordict,tfor)
                  tfor.close()
              elif teach_y_n.upper() in no:
                  print 'Buddy:   Oh! I am eagerly waiting to learn\n\t May be next time.....I hope'
              else:
                  print 'Buddy:   I still dont understand!!'
  print 'Buddy:   Good Bye'                                                   #thats all    
      
      
      
      
      
      
      
      
      
  