蓝桥杯第十届青少年Python组省赛试题
发布时间
阅读量:
阅读量
质因数分解算法:遍历所有小于等于输入数的奇数值,并统计其因数个数。2. 用turtle库绘制树形结构:通过递归函数调用绘制分叉线段,并根据左右偏转角度调整方向。3. 字符串处理与ASCII码转换:将输入字符串中的字符转换为对应ASCII码,并添加到结果字符串中。4. 用turtle库绘制复杂图形:定义递归函数绘制树状结构,并根据输入参数调整分支角度和长度。5. 登录验证系统:读取用户信息文件并进行身份验证与商品信息管理功能。图片: 图片: 图片: 图片:

ns=[1,3,5,8]
cnt=0
for a in ns:
for b in ns:
for c in ns:
if a!=b and a!=c and b!=c:
print(a*100+b*10+c)
cnt+=1
print(cnt)

for i in range(1,1001):
n=str(i)
if '3' in n:
if '33' in n:
n='&'+n
t=True
for j in range(2,i):
if i%j==0:
t=False
break
if t:
n=n+'*'
print(n)


ns=list(map(int,input().split(',')))
print(len(ns))
print(min(ns))
s=''
for n in ns:
if 1<=n<=26:
s+=chr(64+n)
else:
s+='[bad]'
ns.sort(reverse=True)
ns=list(map(str,ns))
print(','.join(ns))
print(s)


import turtle,random
turtle.setup(800,600)
t=turtle.Turtle()
t.speed(7)
t.pensize(5)
t.color('black','yellow')
for i in range(5):
x=random.randint(-400,400)
y=random.randint(-300,300)
t.penup()
t.goto(x,y)
t.pendown()
t.begin_fill()
l=random.randint(10,150)
for j in range(5):
t.forward(l)
t.right(36*4)
t.end_fill()


import turtle
t=turtle.Turtle()
t.left(90)
def fen(n,l):
if n==0:
return
else:
t.left(25)
t.forward(l)
fen(n-1,l-6)
t.backward(l)
t.right(50)
t.forward(l)
fen(n-1,l-6)
t.backward(l)
t.left(25)
fen(4,60)



import turtle,random
turtle.setup(800,600)
turtle.tracer(0)
t=turtle.Turtle()
t.left(90)
def fen(n,l,left,right):
if n==0:
return
else:
t.left(left)
t.forward(l)
fen(n-1,l-6,left,right)
t.backward(l)
t.right(left)
t.right(right)
t.forward(l)
fen(n-1,l-6,left,right)
t.backward(l)
t.left(right)
for i in range(50):
x=random.randint(-400,400)
y=random.randint(-300,300)
t.penup()
t.goto(x,y)
t.pendown()
n=random.randint(4,6)
l=random.randint(30,60)
if x<0:
left,right=20,-5 #偏左边时左右分支要转的角度
else:
left,right=-5,20 #偏左边时左右分支要转的角度
fen(n,l,left,right)





在与当前py代码文件处于同一目录空间中,在与当前py代码文件处于同一目录空间中创建名为userpass.txt的文本框,并按照以下步骤进行操作:首先输入用户名和密码;如果需要将中文内容包含进去,则需注意以下几点:确保编码设置为ANSI,并另存为一个新文件以避免路径问题;最后保存该表单时请确保路径正确无误

在与py代码处于同一目录的文件中,创建名为goods.txt的新文本文件,并向其中添加商品信息。注意:如果商品名称中有中文字符,请先将该文本文件另存为ANSI编码格式,并确保其中心字符集(Chcp)设置为ANSI兼容版本。随后进行保存操作。

001,菠萝,水果,10;002,玫瑰,鲜花,999;003,柚子,水果,20;004,榴莲,水果,30
import random
code=random.randint(100000,999999)
print('您的登录验证码为',code)
n=input('请输入用户名:')
pw=input('请输入密码:')
c=int(input('登录验证码:'))
is_in=True
with open('./userpass.txt','r') as f:
s=f.read()
name,password=s.split(',')
if n==name and pw==password and c==code:
is_in=True
print('身份验证通过,欢迎登录!')
else:
print('身份验证失败!')
if is_in:
with open('./goods.txt','r') as f:
s=f.read()
goods=s.split(';')
for good in goods:
print(good)
while True:
try:
order=input('::')
if order=='add':
good_num=input('商品编号:')
good_name=input('商品名:')
good_type=input('商品类型:')
good_stock=int(input('库存数量:'))
if good_num.strip() and good_name.strip() and good_type.strip() and good_stock:
new_s=good_num+','+good_name+','+good_type+','+str(good_stock)
goods.append(new_s)
s=s+';'+new_s
with open('./goods.txt','w') as f:
f.write(s)
elif order=='count':
cnt=0
for good in goods:
good_datas=good.split(',')
cnt+=int(good_datas[3])
print(cnt)
for good in goods:
print(good)
except Exception as e:
print(e)

全部评论 (0)
还没有任何评论哟~
