《Python少儿编程》同步训练答案.docx

上传人:b****3 文档编号:3537752 上传时间:2022-11-23 格式:DOCX 页数:39 大小:31.29KB
下载 相关 举报
《Python少儿编程》同步训练答案.docx_第1页
第1页 / 共39页
《Python少儿编程》同步训练答案.docx_第2页
第2页 / 共39页
《Python少儿编程》同步训练答案.docx_第3页
第3页 / 共39页
《Python少儿编程》同步训练答案.docx_第4页
第4页 / 共39页
《Python少儿编程》同步训练答案.docx_第5页
第5页 / 共39页
点击查看更多>>
下载资源
资源描述

《Python少儿编程》同步训练答案.docx

《《Python少儿编程》同步训练答案.docx》由会员分享,可在线阅读,更多相关《《Python少儿编程》同步训练答案.docx(39页珍藏版)》请在冰豆网上搜索。

《Python少儿编程》同步训练答案.docx

《Python少儿编程》同步训练答案

第1章走进Python编程世界

1.选择题

(1)C

(2)B(3)C(4)C(5)A

2.简答题

(1)Python具有简单易学、免费开源、类库丰富、可扩展、解释性、可移植性和可嵌入性等特点。

(2)Python的应用领域包括Web开发、网络爬虫、人工智能、数据分析、自动化运营、游戏开发等。

3.编程题

(1)

print('静夜思')

print('——李白')

print('窗前明月光,')

print('疑是地上霜。

')

print('举头望明月,')

print('低头思故乡。

')

(2)

print('i-i-i-i-i')

print('*****************')

print('|:

H-a-p-p-y:

|')

print('~~~~~~~~~~~~~~~~~~~~~~')

print('|:

B-i-r-t-h-d-a-y:

|')

print('**********************')

(3)

print('****')

print('****')

print('**')

print('**')

print('**')

第2章Python编程世界的基础

1.选择题

(1)B

(2)B(3)A(4)A(5)D

2.填空题

(1)字母、数字和下划线数字

(2)9

(3)399.7

(4)False

(5)TrueFalse

3.编程题

(1)

name=input('请输入姓名:

')

age=int(input('请输入年龄:

'))

address=input('请输入地址:

')

print(name,'今年',age,'岁,','地址是',address,'。

')

(2)

price=float(input('请输入商品价格:

'))

amount=int(input('请输入商品数量:

'))

total_price=price*amount

print('商品总价为:

',total_price)

(3)

weight=float(input('请输入您的体重(kg):

'))

height=float(input('请输入您的身高(m):

'))

BMI=weight/(height*height)

print('您的BMI值为:

',BMI)

(4)

episode='东胜神洲傲来国海边有一花果山,山顶一石,承受日月精华,产下一个石猴。

'\

'石猴在花果山做了众猴之王,为求长生,出海求仙,在西牛贺洲拜菩提祖师为师。

'\

'祖师为其取法名孙悟空,并授予七十二般变化及翻筋斗云之法。

'\

'孙悟空回到花果山,占山为王,号为美猴王。

'\

'苦于无兵刃,遂去东海龙宫求取,龙王及兄弟送他一支如意金箍棒及一身披挂。

'\

'孙悟空又去幽冥界把自己的名字从生死簿上勾掉。

'\

'龙王,地藏王上天庭告状,太白金星建议招安孙悟空,玉帝准奏。

'

print('唐僧'inepisode)

print('孙悟空'inepisode)

print('齐天大圣'inepisode)

第3章神奇的分支和循环

1.选择题

(1)A

(2)A(3)C(4)D(5)A

2.填空题

(1)24

(2)201010

(3)①a>b②b=t

(4)15

3.编程题

(1)

weight=float(input('请您输入行李的重量:

'))

ifweight<0:

print('您输入的数据有误!

')

elifweight<=20:

print('您可以免费托运行李!

')

elifweight<=30:

price=(weight-20)*5

print('您的托运费用为',price,'元!

')

elifweight<=40:

price=(30-20)*5+(weight-30)*10

print('您的托运费用为',price,'元!

')

elifweight<=50:

price=(30-20)*5+(40-30)*10+(weight-40)*15

print('您的托运费用为',price,'元!

')

else:

print('您托运的行李超出了最高上限,不允许托运!

')

(2)

forcockinrange(0,20+1):

#鸡翁范围在0到20之间

forheninrange(0,33+1):

#鸡母范围在0到33之间

forbiddyinrange(3,99+1):

#鸡雏范围在3到99之间

if(5*cock+3*hen+biddy/3)==100:

#判断钱数是否等于100

if(cock+hen+biddy)==100:

#判断购买的鸡数是否等于100

ifbiddy%3==0:

#判断鸡雏数是否能被3整除

print('鸡翁:

',cock,'鸡母:

',hen,'鸡雏:

',biddy)#输出

(3)

i=2

whilei<100:

#循环范围为2~100

j=2

whilej

#循环范围为2~i

ifi%j==0:

#如果i能整除j,i不是素数

break#跳出循环

j=j+1

ifj==i:

#范围为2~i的循环结束后,如果j等于i,说明i为素数

print(i)#输出素数

i=i+1

(4)

foriinrange(1,10):

#循环范围为1~9

forjinrange(10-i):

#循环范围为0~9-i

print(end='')#以空格结尾,不换行

forkinrange(10-i,10):

#循环范围为10-i~9

print('*',end='')#以空格结尾,不换行

print('')#换行

第4章形形色色的数据容器

1.选择题

(1)C

(2)B(3)A(4)A(5)B(6)C

2.填空题

(1)helloworlddllohlodlrowolleh

(2)PYTHONSTRINGpythonstring10PythonStrgni

(3)小括号中括号

(4)8

(5){'name':

None,'age':

None,'weight':

None,'height':

None}

(6)forvalueinnum_dict.values():

3.编程题

(1)

flag=True#定义回文串标志,赋初值为True

checkStr=input('请输入要检测的字符串:

')

low=0#定义首字符的索引

high=len(checkStr)-1#定义尾子符的索引

whilelow

#检测首尾两个字符是否相等

ifcheckStr[low]!

=checkStr[high]:

flag=False

low+=1

high-=1

ifflag:

print('“{}”是回文串。

'.format(checkStr))

else:

print('“{}”不是回文串。

'.format(checkStr))

(2)

dictCourse={'吕红':

'数据库',

'周婷':

'线性代数',

'肖扬':

'Python',

'李娟':

'数据库',

'丁锦':

'英语',

'周玲玲':

'Java'}

dictCourse['赵红']='Java'#增加一条信息赵红讲授Java

dictCourse['周玲玲']='Python'#周玲玲改为讲授Python

dictCourse.pop('周婷')#删除周婷授课信息

print('********课程安排信息********')

forteacher,courseindictCourse.items():

print(teacher,course)

print('******所有讲授Python的教师******')

forteacher,courseindictCourse.items():

ifcourse=='Python':

print(teacher,end='')

(3)

dict1={'小蓝':

[123456,0],'小明':

[12345678,0]}#定义字典用于存储用户信息

whileTrue:

#开始循环

name=input('请输入用户名:

')#输入用户名

password=int(input('请输入密码:

'))#输入密码

ifnamenotindict1.keys():

#如果输入的用户名不在字典中

print('该用户名不存在')#输出提示语

continue#结束本次循环

ifdict1[name][1]==2:

#如果次数大于2

print('3次密码错误,该用户名已被锁定')#输出被锁定提示信息

break#跳出循环

ifpassword==dict1[name][0]:

#如果输入的密码正确

print('登录成功')#输出登录成功提示语

break#跳出循环

else:

#密码输入错误

print('用户名或密码错误')#输出提示语

dict1[name][1]+=1#次数加1

(4)

strs=input('请输入一个字符串:

')#输入字符串

setStrs=set(strs)#将字符串转换为集合,去重

listStrs=list(setStrs)#将集合转换为列表

listStrs.sort()#将列表按升序排序

forxinlistStrs:

#输出列表中的所有字符

print(x,end='')

第5章强大的函数积木

1.选择题

(1)C

(2)C(3)A(4)D(5)B(6)D(7)C(8)A

2.填空题

(1)逗号

(2)return

(3)不定长

(4)嵌套

(5)局部

(6)global

(7)75

(8)54

(9)134

(10)1

3.编程题

(1)

defnarcissistic(n):

b=int(n/100)#计算百位数

s=int((n-100*b)/10)#计算十位数

g=n%10#计算个位数

ifn==g**3+s**3+b**3:

#判断数字的立方和是否等于该数本身

return'{}是水仙花数'.format(n)

else:

return'{}不是水仙花数'.format(n)

num=int(input('请输入一个3位整数:

'))

print(narcissistic(num))

(2)

defhano(n,x,y,z):

#n表示层数,x表示起始柱、y表示辅助柱、z表示目标柱

ifn==1:

print(x,'->',z)

else:

hano(n-1,x,z,y)#将n-1个盘子从x->y

print(x,'->',z)#将剩余的最后一个盘子从x->z

hano(n-1,y,x,z)#将剩余的n-1个盘子从y->z

n=int(input('请输入汉诺塔的层数:

'))

hano(n,'A','B','C')

(3)

'''compute.py,定义函数实现加、减、乘、除计算'''

defadd(x,y):

#定义加法方法

print('{}+{}={}'.format(x,y,x+y))

defsub(x,y):

#定义减法方法

print('{}-{}={}'.format(x,y,x-y))

defMultiplication(x,y):

#定义乘法方法

print('{}*{}={}'.format(x,y,x*y))

defdivision(x,y):

#定义除法方法

ify==0:

print('除数不能为0!

')

else:

print('{}/{}={}'.format(x,y,x/y))

'''编程题_3.py,导入compute模块,调用函数计算输入的两个数的和、差、乘和除结果'''

importcompute

x=float(input('请输入第一个数:

'))

y=float(input('请输入第二个数:

'))

compute.add(x,y)

compute.sub(x,y)

compute.Multiplication(x,y)

compute.division(x,y)

第6章会画画的“小海龟”

1.选择题

(1)A

(2)D(3)C(4)C(5)A

2.填空题

(1)设置画笔颜色为红色,填充颜色为黄色

(2)begin_fill()end_fill()

(3)dot(50,'Red')

(4)forward(distance)fd(distance)

(5)画笔移动到(90,0)坐标,然后左转90度

3.编程题

(1)

importturtleast#导入turtle模块为t

defpolygon(n,length):

#绘制正n边形,边长为length

foriinrange(n):

#循环n次

t.forward(length)#前进length

t.left(360/n)#左转角度为正n边形的外角

n=int(input('请输入边数:

'))#输入边数

length=int(input('请输入边长:

'))#输入边长

polygon(n,length)

t.done()

(2)

importturtleast

t.pensize

(2)#设置笔画宽度

#绘制半边黑色图形

t.begin_fill()

t.circle(100,180)

t.seth(0)

t.circle(-50,180)

t.circle(50,180)

t.end_fill()

#绘制半边白色图形

t.seth(180)

t.circle(-100,180)

#绘制黑白两个圆点

t.penup()

t.goto(0,50)

t.pendown()

t.dot(20,'White')

t.penup()

t.goto(0,150)

t.pendown()

t.dot(20,'Black')

t.hideturtle()#隐藏画笔

t.done()#完成

(3)

importturtleast

t.pensize(3)#设置画笔宽度

defdrawCircle(x,y,c):

#绘制一个圆,参数为x、y坐标和画笔颜色

t.pu()#抬起画笔

t.goto(x,y)#移动到圆的起始位置

t.pd()#落下画笔

t.color(c)#设置画笔颜色为c

t.circle(30)#绘制半径为30的圆

drawCircle(0,0,'Blue')#绘制蓝色圆

drawCircle(60,0,'Black')#绘制黑色圆

drawCircle(120,0,'Red')#绘制红色圆

drawCircle(90,-30,'Green')#绘制绿色圆

drawCircle(30,-30,'Yellow')#绘制黄色圆

t.ht()#隐藏画笔

t.done()#完成

(4)

importturtleast

#初始化设置

t.screensize(400,300)

t.pensize(4)#设置画笔的粗细

t.colormode(255)#设置GBK颜色范围为0-255

t.color((255,155,192),'pink')#设置画笔颜色和填充颜色(pink)

t.setup(840,500)#设置主窗口的大小为840*500

t.speed(10)#设置画笔速度为10

defnose():

#绘制鼻子

t.pu()#提笔

t.goto(-100,100)#画笔前往坐标(-100,100)

t.pd()#下笔

t.seth(-30)#笔的角度为-30°

t.begin_fill()#外形填充的开始标志

a=0.4

foriinrange(120):

if0<=i<30or60<=i<90:

a=a+0.08

t.lt(3)#向左转3度

t.fd(a)#向前走a的步长

else:

a=a-0.08

t.lt(3)

t.fd(a)

t.end_fill()#依据轮廓填充

t.pu()#提笔

t.seth(90)#笔的角度为90度

t.fd(25)#向前移动25

t.seth(0)#转换画笔的角度为0

t.fd(10)

t.pd()

t.pencolor(255,155,192)#设置画笔颜色

t.seth(10)

t.begin_fill()

t.circle(5)#画一个半径为5的圆

t.color(160,82,45)#设置画笔和填充颜色

t.end_fill()

t.pu()

t.seth(0)

t.fd(20)

t.pd()

t.pencolor(255,155,192)

t.seth(10)

t.begin_fill()

t.circle(5)

t.color(160,82,45)

t.end_fill()

defhead():

#绘制头

t.color((255,155,192),'pink')

t.pu()

t.seth(90)

t.fd(41)

t.seth(0)

t.fd(0)

t.pd()

t.begin_fill()

t.seth(180)

t.circle(300,-30)#顺时针画一个半径为300,圆心角为30°的圆

t.circle(100,-60)

t.circle(80,-100)

t.circle(150,-20)

t.circle(60,-95)

t.seth(161)

t.circle(-300,15)

t.pu()

t.goto(-100,100)

t.pd()

t.seth(-30)

a=0.4

foriinrange(60):

if0<=i<30or60<=i<90:

a=a+0.08

t.lt(3)#向左转3度

t.fd(a)#向前走a的步长

else:

a=a-0.08

t.lt(3)

t.fd(a)

t.end_fill()

defear():

#绘制耳朵

t.color((255,155,192),'pink')

t.pu()

t.seth(90)

t.fd(-7)

t.seth(0)

t.fd(70)

t.pd()

t.begin_fill()

t.seth(100)

t.circle(-50,50)

t.circle(-10,120)

t.circle(-50,54)

t.end_fill()

t.pu()

t.seth(90)

t.fd(-12)

t.seth(0)

t.fd(30)

t.pd()

t.begin_fill()

t.seth(100)

t.circle(-50,50)

t.circle(-10,120)

t.circle(-50,56)

t.end_fill()

defeye():

#绘制眼睛

t.color((255,155,192),'white')

t.pu()

t.seth(90)

t.fd(-20)

t.seth(0)

t.fd(-95)

t.pd()

t.begin_fill()

t.circle(15)

t.end_fill()

t.color('black')

t.pu()

t.seth(90)

t.fd(12)

t.seth(0)

t.fd(-3)

t.pd()

t.begin_fill()

t.circle(3)

t.end_fill()

t.color((255,155,192),'white')

t.pu()

t.seth(90)

t.fd(-25)

t.seth(0)

t.fd(40)

t.pd()

t.begin_fill()

t.circle(15)

t.end_fill()

t.color('black')

t.pu()

t.seth(90)

t.fd(12)

t.seth(0)

t.fd(-3)

t.pd()

t.begin_fill()

t.circle(3)

t.end_fill()

defcheek():

#绘制腮

t.color((255,155,192))

t.pu()

t.seth(90)

t.fd(-95)

t.seth(0)

t.fd(65)

t.pd()

t.begin_fill()

t.circle(30)

t.end_fill()

defmouth():

#绘制嘴

t.color(239,69,19)

t.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1