第十一届蓝桥杯python组试题(前七题)

第十一届蓝桥杯python组试题

门牌制作

在这里插入图片描述

'''
思路:将数字转换为字符串,然后进行加和求得2个个数
'''
#代码
count = 0
    for i in range(2,2021):
        str1 = str(i)
        if '2' in str1:
            for s in str1:
                if s == '2':
                    count += 1
    print(count)
#代码2:
count = 0
for i in range(1, 2021):
    count += str(i).count('2')
print(count)
#结果
624

寻找2020

在这里插入图片描述

'''
['2', '2', '0', '0', '0', '0'],
['0', '0', '0', '0', '0', '0'], 
['0', '0', '2', '2', '0', '2'],
['0', '0', '0', '0', '0', '0'],
['0', '0', '0', '0', '2', '2'],
['0', '0', '2', '0', '2', '0']
'''

#代码
data = []
count = 0
with open('text.txt','r',encoding='utf-8') as fp:
    for line in fp:
        line = list(line.strip())
        data.append(line)
print(data)

for i in range(len(data)):
    for j in range(len(data[0])):
            if i+3<len(data) and data[i+1][j]=='0' and data[i+2][j]=='2' and data[i+3][j]=='0' and data[i][j]=='2' :
                count += 1
            if j+3<len(data[0]) and data[i][j+1]=='0' and data[i][j+2]=='2' and data[i][j+3]=='0' and data[i][j]=='2':
                count += 1
            if j+3<len(data[0]) and i+3<len(data) and data[i+1][j+1]=='0' and data[i+2][j+2]=='2' and data[i+3][j+3]=='0' and data[i][j]=='2':
                count += 1
print(count)

跑步锻炼

在这里插入图片描述

#代码
import datetime
distance = 0
start_time = datetime.datetime(year=2000,month=1,day=1);
end_time = datetime.datetime(year=2020,month=10,day=1);

while start_time<=end_time:
    if start_time.day == 1 or start_time.weekday() == 0:
        distance += 2
    else:
        distance += 1
    start_time += datetime.timedelta(days=1)
print(distance)
#结果
8879

蛇形填数

在这里插入图片描述
多花几行可以看出中间个数是每次增咋4的n倍
在这里插入图片描述


count = 1
for i in range(1,20):
    count += i*4
print(count)
#结果:
761

排序

在这里插入图片描述

alist =list('jonmlkihgfedcba')
count = 0

for i in range(len(alist) - 1):
    for j in range(len(alist) - 1 - i):
        if alist[j] > alist[j+1]:
            count += 1
            alist[j], alist[j+1] = alist[j+1], alist[j]

print(count)

成绩统计

在这里插入图片描述
在这里插入图片描述

count = int(input())
lst = []
yx = 0
jg = 0
for i in range(count):
    lst.append(int(input()))

for i in range(count):
    if lst[i] >= 60:
        jg += 1
    if lst[i] >= 85:
        yx += 1
yx = int(round(yx/count,2)*100)
jg = int(round(jg/count,2)*100)
print("{0}%".format(jg))
print("{0}%".format(yx))

单词分析

在这里插入图片描述
在这里插入图片描述

str1 = input()
lst = [0 for i in range(25)]

for i in range(len(str1)):
    lst[int(ord(str1[i]) - 97)] += 1
count = max(lst)
print(chr(lst.index(count) + 97))
print(count)
  • 6
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

南岸青栀*

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值