def d01():
# 输入1 - 7,打印对应的星期(例如3,输出‘星期三’)
_t = int(input("请输入1-7任意一个数:"))
_l = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
print(_l[_t-1])
return 1
def d02():
# 计算从1到100以内所有能被3或者17整除的数的和并输出
_s = 0
print("能被3或者17整除的数:", end=" ")
for i in range(1, 101, 1):
if i % 3 == 0 or i % 17 == 0:
print(i, end=",")
_s += i
print()
print("能被3或者17整除的数的和:", _s)
return 1
def d03():
# 计算1到100以内能被7或者3整除但不能同时被这两者整除的数的个数
_s = 0
print("能被7或者3整除但不能同时被这两者整除的数:")
for i in range(1, 101, 1):
if i % 3 == 0 or i % 7 == 0:
if i % 3 == 0 and i % 7 == 0:
continue
else:
print(i, end=",")
_s += 1
print()
print("能被7或者3整除但不能同时被这两者整除的数的个数:", _s)
return 1
def d04():
# 计算从1到1000以内所有能同时被3,5和7整除的数的和并输出
_s = 0
print("能同时被3,5和7整除的数:", end=" ")
for i in range(1, 1001, 1):
if i % 3 == 0 and i % 5 == 0 and i % 7 == 0:
print(i, end=",")
_s += i
print()
print("能同时被3,5和7整除的数的和:", _s)
return 1
def d05():
# 五位数中,对称的数称为回文数,打印所有的回文数并计算个数 例如: 12121 23632.....
_s = 0
for i in range(10000, 99999, 1):
if i // 10000 == i % 10 and i // 1000 % 10 == i % 100 // 10:
print(i)
_s += 1
print("个数:", _s)
return 1
def d06():
# 猜数游戏:
# 输入一个数,如果猜对了,输出:“恭喜你猜对了”,结束游戏;
# 如果猜错了就提示“错了,你输入的数太大了!”或者“错了,你输入的数太小了!”,循环继续猜。
import random
_n = random.randint(1, 100)
while True:
_x = int(input("请输入一个数1-100:"))
if _x < _n:
print("错了,你输入的数太小了!")
elif _x > _n:
print("错了,你输入的数太大了!")
else:
print("恭喜你猜对了")
break
return 1
def d07():
# 双色球,机选5注(红球1 - 33 选5个 蓝球 1 - 16 选1个)
import random
red = []
blue = []
r = 1
b = 1
x = 1
for r in range(1, 34, 1):
red.append(r)
for b in range(1, 17, 1):
blue.append(b)
for x in range(1, 6, 1):
a = random.sample(red, 5) + random.sample(blue, 1)
print(a)
return 1
def d08():
# 双色球,机选5注(红球1 - 33 选5个 蓝球 1 - 16 选1个)
import random
_l = []
i = 0
while i < 5:
_r = random.randint(1, 33)
if _r not in _l:
_l.append(_r)
i += 1
_l.append(random.randint(1, 16))
print(_l)
return 1
d08()
05-05
1615
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-17