练习题
# 问题1: # 编写一个程序,它将找到所有这些数字,可被7整除,但不是5的倍数,2000年至3200年(包括在内)。得到的数字应按逗号分隔的顺序打印在一行上。 # 提示:考虑使用range(#begin, #end)方法 d=[] for i in range(2000, 3201): if i % 7 == 0 and i % 5 != 0: d.append(i) print(d)
# 问题4: # 将字符串 res = 'without,hello,bag,world' 排序输出 # bag,hello,without,world res = 'without,hello,bag,world' res = res.split(',') res = sorted(res) print(','.join(res))
# 问题3(两种方法): # 编写一个程序,将res里面的数字按照‘,‘隔开提取出来并输出成列表和元租打印出来 # res = '34岁,67年,55岁,kkkkkk33岁,12日,98年' # 则输出为:[‘34’, ‘67’, ‘55’, ‘33’, ‘12’, ‘98’] # (‘34’, ‘67’, ‘55’, ‘33’, ‘12’, ‘98’) res = '34岁,67年,55岁,kkkkkk33岁,12日,98年' import re c_int = re.findall('\d{2}', res) print(c_int) d = [] for i in res: if i.isdigit(): d.append(i) else: continue c = '' d = [] for i in res: if i.isdigit(): c += i elif c: d.append(c) c = '' if c: d.append(c) print(d)
d = [] res = res.split(',') for i in res: print(i) c = '' for j in i: print(j) if j.isdigit(): c += j d.append(c) print(d) c = tuple(d) print(c)
# 使用给定的整数n,编写一个程序生成一个包含(i, i*i)的字典,该字典包含1到n之间的整数(两者都包含)。然后程序应该打印字典。 # 假设向程序提供以下输入:8 # 则输出为: # {1:1,2:4,3:9,4:16,5:25,6:36,,7:49,8:64} def inner(n): d = {} for i in range(1, n + 1): j = i * i d[i] = j return d res = inner(8) print(res)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY