精华内容
下载资源
问答
  • 主要为大家详细介绍了人机交互程序,初步实现python人机对话,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • 导读热词自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了...

    导读热词

    自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)

    # hello.py

    # 这是老早写的。不过今天加入了Pickle,然后润色了一下。

    # 可能有点无聊(不推荐使用)

    import pickle

    import os.path

    def search(x,data):

    for k,d in enumerate(data):

    if x == d['name']:

    return k,d

    def save_data(A,pklname):

    with open(pklname,'wb') as pkl:

    pickle.dump(A,pkl)

    def load_data(pklname):

    with open(pklname,'rb') as pkl:

    return pickle.load(pkl)

    # communicating with computer

    data=[] if not os.path.isfile('data') else load_data('data')

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?\n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name,data):

    print('--Welcome,'+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    data.append(d)

    else:

    print('--Hi,'+name+'. How I miss you.')

    k,d=search(name,data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Y'}:

    print('--%s. [the data is saved in file named "data".]'%y)

    save_data(data,'data')

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    下面是hello.py的面向对象编程版本(推荐)

    # hello.py

    import pickle

    import os.path

    def search(x,d

    class Hello:

    def __init__(self,name='',data=None):

    self.name = name

    self.data = data

    def __getstate__(self):

    return self.data

    def __setstate__(self,data):

    self.data = data

    def mainloop(self):

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?\n--')

    if name in {'quit','Q'}:

    print('[You quit]')

    break

    if not search(name,self.data):

    print('--Welcome,'+name+ '. I will remember you name.')

    d={'name':name,'history':[]}

    self.data.append(d)

    else:

    print('--Hi,'+name+'. How I miss you.')

    k,self.data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); self.data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); self.data[k]=d

    if y in {'no','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Y'}:

    print('--%s. [the data is saved in file named "data.pkl".]'%y)

    with open('data.pkl','wb') as fo:

    pickle.dump(self,fo)

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    # communicating with computer

    try:

    with open('data.pkl','rb') as fo:

    hello=pickle.load(fo)

    except:

    hello=Hello('ai',[])

    hello.mainloop()

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

    相关文章

    总结

    如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

    本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。

    如您喜欢交流学习经验,点击链接加入交流1群:1065694478(已满)交流2群:163560250

    展开全文
  • 自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了一下。# ...

    自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)

    # hello.py

    # 这是老早写的。不过今天加入了Pickle,然后润色了一下。

    # 可能有点无聊(不推荐使用)

    import pickle

    import os.path

    def search(x, data):

    for k, d in enumerate(data):

    if x == d['name']:

    return k, d

    def save_data(A,pklname):

    with open(pklname, 'wb') as pkl:

    pickle.dump(A, pkl)

    def load_data(pklname):

    with open(pklname, 'rb') as pkl:

    return pickle.load(pkl)

    # communicating with computer

    data=[] if not os.path.isfile('data') else load_data('data')

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?\n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name, data):

    print('--Welcome, '+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    data.append(d)

    else:

    print('--Hi, '+name+'. How I miss you.')

    k, d=search(name, data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','No','n','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Yes','y','Y'}:

    print('--%s. [the data is saved in file named "data".]'%y)

    save_data(data, 'data')

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    下面是hello.py的面向对象编程版本(推荐)

    # hello.py

    import pickle

    import os.path

    def search(x, data):

    for k, d in enumerate(data):

    if x == d['name']:

    return k, d

    class Hello:

    def __init__(self, name='', data=None):

    self.name = name

    self.data = data

    def __getstate__(self):

    return self.data

    def __setstate__(self, data):

    self.data = data

    def mainloop(self):

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?\n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name, self.data):

    print('--Welcome, '+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    self.data.append(d)

    else:

    print('--Hi, '+name+'. How I miss you.')

    k, d=search(name, self.data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); self.data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); self.data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','No','n','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Yes','y','Y'}:

    print('--%s. [the data is saved in file named "data.pkl".]'%y)

    with open('data.pkl', 'wb') as fo:

    pickle.dump(self, fo)

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    # communicating with computer

    try:

    with open('data.pkl', 'rb') as fo:

    hello=pickle.load(fo)

    except:

    hello=Hello('ai',[])

    hello.mainloop()

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

    展开全文
  • 自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了一下。# ...

    自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)

    # hello.py

    # 这是老早写的。不过今天加入了Pickle,然后润色了一下。

    # 可能有点无聊(不推荐使用)

    import pickle

    import os.path

    def search(x, data):

    for k, d in enumerate(data):

    if x == d['name']:

    return k, d

    def save_data(A,pklname):

    with open(pklname, 'wb') as pkl:

    pickle.dump(A, pkl)

    def load_data(pklname):

    with open(pklname, 'rb') as pkl:

    return pickle.load(pkl)

    # communicating with computer

    data=[] if not os.path.isfile('data') else load_data('data')

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name, data):

    print('--Welcome, '+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    data.append(d)

    else:

    print('--Hi, '+name+'. How I miss you.')

    k, d=search(name, data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','No','n','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Yes','y','Y'}:

    print('--%s. [the data is saved in file named "data".]'%y)

    save_data(data, 'data')

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    下面是hello.py的面向对象编程版本(推荐)

    # hello.py

    import pickle

    import os.path

    def search(x, data):

    for k, d in enumerate(data):

    if x == d['name']:

    return k, d

    class Hello:

    def __init__(self, name='', data=None):

    self.name = name

    self.data = data

    def __getstate__(self):

    return self.data

    def __setstate__(self, data):

    self.data = data

    def mainloop(self):

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name, self.data):

    print('--Welcome, '+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    self.data.append(d)

    else:

    print('--Hi, '+name+'. How I miss you.')

    k, d=search(name, self.data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); self.data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); self.data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','No','n','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Yes','y','Y'}:

    print('--%s. [the data is saved in file named "data.pkl".]'%y)

    with open('data.pkl', 'wb') as fo:

    pickle.dump(self, fo)

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    # communicating with computer

    try:

    with open('data.pkl', 'rb') as fo:

    hello=pickle.load(fo)

    except:

    hello=Hello('ai',[])

    hello.mainloop()

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持积木网。

    Python 将RGB图像转换为Pytho灰度图像的实例

    问题:我正尝试使用matplotlib读取RGB图像并将其转换为灰度。在matlab中,我使用这个:img=rgb2gray(imread('image.png'));在matplotlibtutorial中他们没有覆盖它。他们

    python中os和sys模块的区别与常用方法总结

    前言本文主要介绍了关于python中os和sys模块区别与常用方法的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看看详细的介绍吧。官方解

    Python利用multiprocessing实现最简单的分布式作业调度系统实例

    介绍Python的multiprocessing模块不但支持多进程,其中managers子模块还支持把多进程分布到多台机器上。一个服务进程可以作为调度者,将任务分布到其他多

    展开全文
  • 自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了一下。# ...

    自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)

    # hello.py

    # 这是老早写的。不过今天加入了Pickle,然后润色了一下。

    # 可能有点无聊(不推荐使用)

    import pickle

    import os.path

    def search(x, data):

    for k, d in enumerate(data):

    if x == d['name']:

    return k, d

    def save_data(A,pklname):

    with open(pklname, 'wb') as pkl:

    pickle.dump(A, pkl)

    def load_data(pklname):

    with open(pklname, 'rb') as pkl:

    return pickle.load(pkl)

    # communicating with computer

    data=[] if not os.path.isfile('data') else load_data('data')

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?\n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name, data):

    print('--Welcome, '+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    data.append(d)

    else:

    print('--Hi, '+name+'. How I miss you.')

    k, d=search(name, data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','No','n','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Yes','y','Y'}:

    print('--%s. [the data is saved in file named "data".]'%y)

    save_data(data, 'data')

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    下面是hello.py的面向对象编程版本(推荐)

    # hello.py

    import pickle

    import os.path

    def search(x, data):

    for k, d in enumerate(data):

    if x == d['name']:

    return k, d

    class Hello:

    def __init__(self, name='', data=None):

    self.name = name

    self.data = data

    def __getstate__(self):

    return self.data

    def __setstate__(self, data):

    self.data = data

    def mainloop(self):

    while True:

    print('Welcome! [type "quit" if you want to quit.]')

    name=input('--What is your name?\n--')

    if name in {'quit','Quit','q','Q'}:

    print('[You quit]')

    break

    if not search(name, self.data):

    print('--Welcome, '+name+ '. I will remember you name.')

    d={'name':name,'age':0,'history':[]}

    self.data.append(d)

    else:

    print('--Hi, '+name+'. How I miss you.')

    k, d=search(name, self.data)

    while d['age']==0:

    age=input('--How old are you?[I will repeat until you respond!]')

    try:

    if int(age)==0: continue

    d['age']=int(age); self.data[k]=d

    except:

    pass

    while True:

    y=input('--Chan I help you? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    d['history'].append(y); self.data[k]=d

    if y in {'no','No','n','N'}:

    print('--%s.'%y)

    print('--Bye bye.')

    break

    elif y in {'yes','Yes','y','Y'}:

    print('--%s.'%y)

    print('I am pleased to serve you.')

    else:

    print('I am sorry. I can not understand what you said.')

    break

    # save data

    y=input('--Do you want to save the data? [yes/no]')

    while not y:

    y=input('--Yes or no?')

    if y in {'no','No','n','N'}:

    print('--%s. [You say no.]'%y)

    elif y in {'yes','Yes','y','Y'}:

    print('--%s. [the data is saved in file named "data.pkl".]'%y)

    with open('data.pkl', 'wb') as fo:

    pickle.dump(self, fo)

    else:

    print('I am sorry. I can not understand what you said. data are not saved.')

    # communicating with computer

    try:

    with open('data.pkl', 'rb') as fo:

    hello=pickle.load(fo)

    except:

    hello=Hello('ai',[])

    hello.mainloop()

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

    时间: 2017-11-13

    展开全文
  • Python实现人机对话

    千次阅读 2019-09-16 10:13:34
    朋友们,我是床长!... 【前言】  AI  在人工智能进展的如火如荼的今天,我们如果不尝试去接触新鲜事物,马上就要被世界淘汰啦~ ...最终达到人机对话的效果。 【实现功能】  这篇文章将要介绍...
  • {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],"search_count":[{"count_phone":4,"count":4}]},"card":[{"des":"阿里技术对外发布原创技术内容的最大平台;社区覆盖了云计算、大数据、人工智能、...
  • 自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了一下。# ...
  • 最终达到人机对话的效果。 【实现功能】 这篇文章将要介绍的主要内容如下:  1、搭建人工智能–人机对话服务端平台  2、实现调用服务端平台进行人机对话交互 【实现思路】  AIML  AIML由Richard Wallace发明。...
  • 自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了一下。# ...
  • 在人工智能进展的如火如荼的今天,...【实现功能】这篇文章将要介绍的主要内容如下:1、搭建人工智能--人机对话服务端平台2、实现调用服务端平台进行人机对话交互【实现思路】AIMLAIML由Richard Wallace发明。他设计...
  • 自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。 (推荐面向对象版本)# hello.py# 这是老早写的。不过今天加入了Pickle,然后润色了一下。# ...
  • 在人工智能进展的如火如荼的今天,我们如果不尝试去...【实现功能】这篇文章将要介绍的主要内容如下:1、搭建人工智能--人机对话服务端平台2、实现调用服务端平台进行人机对话交互【实现思路】AIMLAIML由Richard Wal...
  • AI人工智能-Python实现人机对话

    万次阅读 2017-12-12 16:56:07
    【前言】  AI  在人工智能进展的如火如荼的今天,我们如果不尝试去接触新鲜事物,马上就要被世界淘汰啦~  本文拟使用Python开发语言实现类似于WIndows平台的“小娜”... 2、实现调用服务端平台进行人机对话交互
  • 【注意】如何应对江苏省初中英语听力口语自动化考试?什么是江苏省初中英语听力口语自动化考试?...英语听力口语考试分听力和口语两部分:听力部分采用“听对话回答问题”和“听对话和短文回答问...
  • 【前言】AI在人工智能进展的如火如荼的今天,...【实现功能】这篇文章将要介绍的主要内容如下:1、搭建人工智能--人机对话服务端平台2、实现调用服务端平台进行人机对话交互【实现思路】AIMLAIML由Richard Wallace...
  • python 初步实现人机对话

    千次阅读 2015-10-11 22:03:07
    有点无聊,自己随便写了一个人机交互的程序。不存在任何智能,只是可以识别姓名,可以记录对话内容,并保存等到下一次交互时加载。(推荐面向对象版本) 已经发布到Github: [assistant]...
  • 【前言】AI在人工智能进展的如火如荼的今天,我们如果不...【实现功能】这篇文章将要介绍的主要内容如下:1、搭建人工智能--人机对话服务端平台2、实现调用服务端平台进行人机对话交互【实现思路】AIMLAIML由Richa...
  • 最终达到人机对话的效果。 【实现功能】 这篇文章将要介绍的主要内容如下:  1、搭建人工智能–人机对话服务端平台  2、实现调用服务端平台进行人机对话交互 【实现思路】 AIML  AIML由Richard ...
  • b、基于python3。c、也有自己的签名生成这块,有了鹅厂的底子,相对写起来比较简单。d、不过Sougou明显在接口标准化这块明显不如鹅厂,不同api应答包的主体结构竟然不一致,所以实施也只做了简单的结构化……2、实现...

空空如也

空空如也

1 2 3 4 5 ... 8
收藏数 151
精华内容 60
关键字:

人机对话python

python 订阅