# 问题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)