python测试题-列表,字典,字符串
1,如何实现"1,2,3"变成[‘1’,‘2’,‘3’]? 如何实现[‘1’,‘2’,‘3’]变成[1,2,3]?
a ='1,2,3'
python基础知识测试题print(a.split(','))
结果['1','2','3']
b =['1','2','3']
print(list(map(lambda x:int(x), b)))
2,1,2,3,4,5能组成多少个互不相同且⽆重复的三位数?
print([(i, j, k)for i in range(1,6)for j in range(1,6)for k in range(1,6)if i != k and i != j and j != k])
输出结果为:
[(1,2,3),(1,2,4),(1,2,5),(1,3,2),(1,3,4),(1,3,5),(1,4,2),(1,4,3),(1,4,5),(1,5,2),(1,5,3),(1,5,4),(2,1,3),(2,1,4),(2,
1,5),(2,3,1),(2,3,4 ),(2,3,5),(2,4,1),(2,4,3),(2,4,5),(2,5,1),(2,5,3),(2,5,4),(3,1,2),(3,1,4),(3,1,5),(3,2,1),(3,2,4),(3,2,5),(3,4,1),(3,4,2),(3,4,5),(3,5, 1),(3,5,2),(3,5,4),(4,1,2),(4,1,3),(4,1,5),(4,2,1),(4,2,3),(4,2,5),(4,3,1),(4,3,2),(4,3,5),(4,5,1),(4,5,2),(4,5,3),(5,1,2),(5,1,3),(5,1 ,4),(5,2,1),(5,2,3),(5,2,4),(5,3,1),(5,3,2),(5,3,4),(5,4,1),(5,4,2),(5,4,3)]进程和线程的区别 面试
3,有两个6⾯的筛⼦,同时抛掷100000次,求两个筛⼦点数之和所占的百分⽐?(输出字典形式)
def count_tt():
res =list()
for i in range(10000):
a = random.randint(1,6)
bootstrap前端模板怎么用b = random.randint(1,6)
res.append(a + b)
res_d =dict()
for i in set(res):
res_d[i]="{:.2%}".unt(i)/10000)指针等于数组名
print(res_d)
count_tt()
输出结果为:
异步fifo是大学里哪门课{2:'2.831%',3:'5.499%',4:'8.308%',5:'10.965%',6:'13.916%',7:'16.805%',8:'13.897%',9:'11.112%',10:'8.281%',11:'5.495%',12:'2.891%'}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论