while testcount < 100:
num1=randint(0,10)
num2=randint(0,10)
num3=randint(0,10)
num4=randint(0,10)
num5=randint(0,10)
numo=[num1,num2,num3,num4,num5]
if #there are two 7s# in numo:
testcount=testcount+1
num_of_successes=num_of_successes+1
else:
testcount=testcount+1
print(num_of_successes,"out of 100 there were two 7s")
如何检测“numo”中是否有两个 7? 即使它没有使用很多代码。
最佳答案
对于一个列表,可以使用count()
函数来查询count函数传入的参数
中的元素在列表中有多少。
例子-
>>> l = [1,2,3,4,5,6,4]
>>> l.count(4)
2
关于Python检测字符串中的两个相同的东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30994829/