python第六章习题答案6.1
import random
s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789"
L=list(s)
T=0
print("⽣成的密码是:")
while T<10:
pwd = ""
random pythonfor i in range(8):
pwd += L[random.randint(0,len(L)-1)]
print("{}".format(pwd))
T=T+1
print("END")
6.2
def Test(ls):
tem = set(ls)
if len(tem) == len(ls):
print('False')
else:
print('True')
def getTest():
lis = []
ch = input("请输⼊判定元素,回车表⽰结束:")
while ch != '':
lis.append(ch)
ch = input("请输⼊判定元素,回车表⽰结束:")
Test(lis)
getTest()
6.4
str = input("请输⼊要分析的字符串,回车表⽰结束:")
while str != '':
counts = {}
for ch in str:
counts[ch] = (ch,0) + 1
items = list(counts.items())
items.sort(key= lambda x : x[1],reverse= True)
for i in range(len(items)):
word, count = items[i]
print("{0:<10}{1:>5}".format(word, count))
str = input("请输⼊要分析的字符串,回车表⽰结束:")
`6.5
import random
times = 1000*1000
count = 0
for i in range(times):
lis = []
for j in range(23):
lis.append(random.randint(1,365))
items = set(lis)
if len(items) != len(lis):
count += 1
print("⾄少两⼈⽣⽇相同的概率:{:.2f}%".format(count/times*100))

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。