涉及考试:计算机学会编程能力等级认证(GESP)、电子学会等级考试 活动内容:提供不同等级的真题供小朋友们选择练习 备考建议:根据自己备考的等级选择相应题目 附加价值:可作为白名单比赛的备考训练 本月打卡:本月CIE_Python打卡题目
要求:
(1)画一个边长为400的正方形,然后将其平均分割成4份,分割线相交于一点,形成一个田字格,效果如下图:

(2)正方形的边框为黑色,分割线的颜色为红色;
(3)分割线的交点为画布的中心;
(4)最后海龟要隐藏。
参考程序:
注意:仅供参考,考生可以自行设计,结果符合题意即可。
import turtleturtle.penup()turtle.goto(-200, -200)turtle.pendown()for i in range(4): turtle.forward(400) turtle.left(90)turtle.pencolor('red')turtle.penup()turtle.goto(-200, 0)turtle.pendown()turtle.goto(200, 0)turtle.penup()turtle.goto(0, -200)turtle.pendown()turtle.goto(0, 200)turtle.hideturtle()turtle.done()编写程序帮老师对英语试卷中的英文字母、数字和其他字符(注意:包括空格)进行分类并统计每种字符的数量。
输入样例:
**Welcome to 2023~!输出样例:
字母:Welcometo,共9个数字:2023,共4个其它字符:** ~!,共6个参考程序:
注意:仅供参考,考生可以自行设计,结果符合题意即可。
程序1:
dic = {'字母': ['', 0], '数字': ['', 0], '其它字符': ['', 0]}s = input()for i in s:if i.lower() in'abcdefghijklmnopqrstuvwxyz': dic['字母'][0] += i dic['字母'][1] += 1elif i in'0123456789': dic['数字'][0] += i dic['数字'][1] += 1else: dic['其它字符'][0] += i dic['其它字符'][1] += 1print('字母:{},共{}个'.format(dic['字母'][0],dic['字母'][1]))print('数字:{},共{}个'.format(dic['数字'][0],dic['数字'][1]))print('其它字符:{},共{}个'.format(dic['其它字符'][0],dic['其它字符'][1]))程序2:
s = input()letter = ''number = ''other = ''for i in s:if i >= 'a'and i <= 'z'or i >= 'A'and i <= 'Z': letter += ielif i >= '0'and i <= '9': number += ielse: other += iprint('字母:{},共{}个'.format(letter, len(letter)))print('数字:{},共{}个'.format(number, len(number)))print('其它字符:{},共{}个'.format(other, len(other)))程序3:
s = input()letter = ''number = ''other = ''for i in s:if i.isalpha(): letter += ielif i.isdigit(): number += ielse: other += iprint('字母:{},共{}个'.format(letter, len(letter)))print('数字:{},共{}个'.format(number, len(number)))print('其它字符:{},共{}个'.format(other, len(other)))下面程序,按字典序列统计出单词的个数,执行结果如下:
are:2first:2happy:1is:3your:2请补全下列代码中的①②③④四处。
a = ['is', 'happy', 'is', 'your', 'are', 'first', 'first', 'is', 'are', 'your']n = len(a) - 1for i in range(0, n):for j in range(i + 1, n + 1):if a[i] > a[j]: __①___key = a[0]i = 1ans = 1while i <= n:if key == a[i]: __②___ i += 1else: print(a[i - 1] + ':' + str(ans)) key = a[i] __③___ i += 1__④___参考答案:
① a[i], a[j] = a[j], a[i] 或等效答案;
② ans = ans + 1 或等效答案;
③ ans = 1 或等效答案;
④ print(a[i-1] + ':' + str(ans)) 或等效答案;
有一只蜗牛在井底,井深n米。蜗牛每天往上爬a米,又会往回滑b米。请从键盘接收输入整数n,a,b,用空格隔开。并完成下列程序,计算蜗牛爬出这口井需要几天。
n, a, b = input("请输入井深,蜗牛每天往上爬几米,蜗牛滑下几米:")._____①_____ n, a, b = _____②_____ pos = 0i = 0while _____③_____: _____④_____ _____⑤_____ print("第%d天,蜗牛距离井口%d米;" % (i, n - pos))print("第%d天,蜗牛成功离开了深井!!" % (_____⑥_____)) 参考答案:
① split()
② int(n), int(a), int(b)
③ pos + a < n
④ i += 1
⑤ pos += (a - b)
⑥ i + 1
青少年编程竞赛交流
「青少年编程竞赛交流群」已成立(适合6至18周岁的青少年),添加小助手微信,让他邀请大家进入学习群。进群之后大家可以参与定期组织的21天刷题打卡、等级考试测评、教育部白名单比赛辅导以及青少年编程组队竞赛等活动。
