Python 对于数组中的每10个。计数(1)

Python 对于数组中的每10个。计数(1),python,arrays,count,Python,Arrays,Count,所以我得到了一组1到6的骰子卷 因此,我使用.count计算1在数组中运行的次数,但每次该计数超过10时,我还必须打印一些内容。所以,如果我掷100次,得到23次1,我希望它每10次显示一个* 到目前为止,守则是: import random die_rolls = [] maxsize = int(input("What is the maximum die rolls: ")) + 1 for num in range(1,maxsize): die_random = rand

所以我得到了一组1到6的骰子卷

因此,我使用.count计算1在数组中运行的次数,但每次该计数超过10时,我还必须打印一些内容。所以,如果我掷100次,得到23次1,我希望它每10次显示一个*

到目前为止,守则是:

import random

die_rolls = []

maxsize = int(input("What is the maximum die rolls: ")) + 1

for num in range(1,maxsize):
    die_random = random.randint (1,6)
    die_rolls.append(die_random)

print(str(maxsize-1) + " total rolls.")
percent_one = die_rolls.count(1) / maxsize *100

print("1: " + "[" + str(die_rolls.count(1)) + " |", "{:.1f}".format(percent_one) + "%]")

total=sum(die_rolls)
print(total)
我得到:

What is the maximum die rolls: 100
100 total rolls.
1: [21 | 20.8%]
329
我需要它看起来像:

What is the maximum die rolls: 100
100 total rolls.
1: ** [21 | 20.8%]
329
你是说像这样吗

stars = "*" * (die_rolls.count(1) // 10)
print("1: " + stars + " [" + str(die_rolls.count(1)) + " |", "{:.1f}".format(percent_one) + "%]")
//运算符执行整数除法,因此19//10=1、20//10=2、21//10=2等

写入“*”*2使Python将字符串“*”重复两次

编辑:根据@Ev.Kounis save die_rolls.count(1)的建议,将其添加到变量中。
例如,
count\u one=die\u rolls.count(1)

我会保存
die\u rolls.count(1)
。你像那样数两次元素,如果
die\u rolls
足够大,这将产生不同。你到底在问什么?显然,在
“1:”+“[”
之间肯定有什么东西。你试过什么吗?你遇到了什么问题?顺便说一句,
范围(1,maxsize)
只会让你
maxsize-1
滚动。只需使用
范围(maxsize)
就可以了。很抱歉,这让mkrieger1感到困惑,我没有在
“1:”[“之间添加任何东西。”
因为我不知道要添加什么,所以我把它的样子放进去,它应该显示什么,感谢
范围(maxsize)
提示,由于复杂,我不得不与编写此代码的其他人合作。感谢您完全忘记了整数除法。
stars = '*' * (die_rolls.count(1) // 10)  # count number of stars
print('1: {0} [{1} | {2:.1f}%]'.format(stars, die_rolls.count(1), percent_one))