不懂就问2022-10-18-01 硬币试验,运行了一下,怎么总出问题,数量对不上
"""------硬币试验加强版1.0------"""import random
counts = int(input("请输入抛硬币的次数:"))
if counts < 100:
ignore = False
else:
ignore = True
heads = 0
tails = 0
i = 0
print("开始抛硬币试验...")
while i < counts:
num = random.randint(1,10)
if num % 2:
heads = heads + 1
if not ignore:
print("正面",end=" ")
else:
tails += 1
if not ignore:
print("反面",end=" ")
i = i + 1
print("")
print("一共模拟了", counts ,"次抛硬币,结果如下:",sep="")
print("正面:",heads,"次",sep="")
print("反面:",heads,"次",sep="")
各位,帮忙看一下,哪里出错了? 本帖最后由 jackz007 于 2022-10-18 12:55 编辑
print("正面:",heads,"次",sep="")
print("反面:",heads,"次",sep="") # 反面次数显然应该是 tails
正面反面用了同一个变量,焉能对得上!
import random
print("开始抛硬币试验...")
counts = int(input("请输入抛硬币的次数:"))
d =
if counts < 100 :
for x in d :
print('正面') if x else print('反面')
print('总共抛币 %d 次,其中,正面 %d 次,反面 %d 次。' % (counts , sum(d) , counts - sum(d))) 想找个地缝钻进去{:5_103:}
页:
[1]