如何计算乘法次数 python
how to counter Multiply times python
我是 python 的新手,有一些问题想问
问题是如何计算乘数
有6个骰子架
import random
from collections import Counter
amt = 1
point = 0
diceStand = 6
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
dice3 = random.randint(1,6)
dice4 = random.randint(1,6)
dice5 = random.randint(1,6)
dice6 = random.randint(1,6)
roll = [dice1,dice2,dice3,dice4,dice5,dice6]
print("Do you want to play a dice game?")
print("turn " , amt , " of 3")
print("You have", point,'point')
print("You Roll")
for k in range(1):
print(roll)
counts = Counter(roll)
print (Counter(counts))
结果:
[4, 1, 5, 6, 1, 4]
Counter({4: 2, 1: 2, 5: 1, 6*1})
如何打印消息和计数器乘数
比如 4*3 = 12 和 1*2 = 2
只有超过2次才会相乘
那么已经使用了4个骰子
但你也可以掷剩余的骰子,即 2 个骰子 1 次
然后 12 和 2 将保存到点
尝试 3 次后游戏结束
很想了解如何使用随机值和计数器
谢谢
如果我没理解错的话,您想打印任何重复掷骰子的结果,例如如果你掷四次“2”,打印“2 * 4 = 8”
如果是这样的话,那么这样的事情就可以了:
import random
amt = 1
point = 0
diceStand = 6
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
dice3 = random.randint(1,6)
dice4 = random.randint(1,6)
dice5 = random.randint(1,6)
dice6 = random.randint(1,6)
roll = [dice1,dice2,dice3,dice4,dice5,dice6]
print("Do you want to play a dice game?")
print("turn " , amt , " of 3")
print("You have", point,'point')
print("You Roll")
for i in range(1,7):
total = 0
for die in roll:
if i == die:
total += 1
print i, " * ", total, " = ", i*total
编辑:这是一个示例输出
Do you want to play a dice game?
('turn ', 1, ' of 3')
('You have', 0, 'point')
You Roll
1 * 1 = 1
2 * 0 = 0
3 * 2 = 6
4 * 2 = 8
5 * 1 = 5
6 * 0 = 0
我是 python 的新手,有一些问题想问
问题是如何计算乘数
有6个骰子架
import random
from collections import Counter
amt = 1
point = 0
diceStand = 6
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
dice3 = random.randint(1,6)
dice4 = random.randint(1,6)
dice5 = random.randint(1,6)
dice6 = random.randint(1,6)
roll = [dice1,dice2,dice3,dice4,dice5,dice6]
print("Do you want to play a dice game?")
print("turn " , amt , " of 3")
print("You have", point,'point')
print("You Roll")
for k in range(1):
print(roll)
counts = Counter(roll)
print (Counter(counts))
结果:
[4, 1, 5, 6, 1, 4]
Counter({4: 2, 1: 2, 5: 1, 6*1})
如何打印消息和计数器乘数 比如 4*3 = 12 和 1*2 = 2 只有超过2次才会相乘
那么已经使用了4个骰子
但你也可以掷剩余的骰子,即 2 个骰子 1 次 然后 12 和 2 将保存到点 尝试 3 次后游戏结束
很想了解如何使用随机值和计数器 谢谢
如果我没理解错的话,您想打印任何重复掷骰子的结果,例如如果你掷四次“2”,打印“2 * 4 = 8”
如果是这样的话,那么这样的事情就可以了:
import random
amt = 1
point = 0
diceStand = 6
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
dice3 = random.randint(1,6)
dice4 = random.randint(1,6)
dice5 = random.randint(1,6)
dice6 = random.randint(1,6)
roll = [dice1,dice2,dice3,dice4,dice5,dice6]
print("Do you want to play a dice game?")
print("turn " , amt , " of 3")
print("You have", point,'point')
print("You Roll")
for i in range(1,7):
total = 0
for die in roll:
if i == die:
total += 1
print i, " * ", total, " = ", i*total
编辑:这是一个示例输出
Do you want to play a dice game?
('turn ', 1, ' of 3')
('You have', 0, 'point')
You Roll
1 * 1 = 1
2 * 0 = 0
3 * 2 = 6
4 * 2 = 8
5 * 1 = 5
6 * 0 = 0