本程序使用方法:在命令提示符下输入 play.py 你好。然后就会弹出一个窗口,一个机器人会随机挑选一句话进行回答。

以下是部分代码预览:
from turtle import Turtle,Screen
from time import sleep
from random import choice
import sys
def init_screen(width,height,title,picture):
"""新建屏幕对象,参数说明:
width:宽度
height:高度
title:标题
picture:背景图(png)
"""
screen = Screen()
screen.title(title)
screen.setup(width,height)
screen.bgpic(picture)
screen.delay(0)
return screen
def make_sprite(image,x,y):
"""显示角色,参数说明:
image:角色的造型图片,gif
x,y:坐标
"""
t = Turtle(visible=False)
t.penup()
t.shape(image)
t.goto(x,y)
t.showturtle()
def draw_frame(t,startpos,endpos,thickness,color):
"""画框,参数说明:
t:海龟对象
startpos:起始坐标
endpos:结束坐标
thickness:比触宽度
color:颜色
"""
def say_sentence(t,startpos,sentence):
"""写文字,参数说明:
t:海龟对象
startpos:起始位置
info:要写的文字
"""
t.goto(startpos)
for word in sentence:
sleep(0.1)
t.write(word,move=True,font=("楷体",20,"normal"))
if __name__ == "__main__":
hellos = ["你也好","How are you","Hi,我是机器人9号","Hi there!"]
answer_names = ['My name is whitedog','我的名字是小白','我叫白居易','我是Mr White']
answer_play = ['会啊','这是我最拿手的','想玩什么?','好哇']
answer_qq = ['qq游戏最好玩了','qq是1234567','qq啊,我玩qq空间。']
answer_weixin = ['我也常玩微信呢','机器人已经内置微信功能了','微信已经被淘太了。']
answer_fly = ['这个功能科学家还在开发中。','我不能飞。','你看我这样子像能飞的吗?']
answer_jump = ['宝宝不会跳哟。','我不能跳。','你看我这样子像能跳的吗?']
title = "和电脑对话"
screen.exitonclick()
下载完整源代码与素材,请
需要浏览更多吗?
成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)
