【发布时间】:2021-05-14 17:03:00
【问题描述】:
我试图让它不管输入的数字是多少,它都会进行计算,我在 python 方面不是很有经验,我正在做一些会有“x”边数的骰子,它会寻找'x' 对的数量来查看例如掷出 6 个六点需要多少次骰子。对不起,如果我措辞不好
时间是它掷骰子的次数
对是它正在寻找的对的数量
边数是骰子的边数/数
import random
sides = int(input("How many Dice Sides/Numbers: "))
pairs = int(input("How many Pairs to Search for: "))
time = 0
if pairs == 2:
while True:
time += 1
one = random.randint(1, sides)
two = random.randint(1, sides)
if one == two:
break
if pairs == 3:
while True:
time += 1
one = random.randint(1, sides)
two = random.randint(1, sides)
three = random.randint(1, sides)
if one == two and two == three:
break
input(f"Found a Pair after {time} times.")
即我如何使它与我为配对输入的任何数字一起工作,如果这不可能,再次抱歉
【问题讨论】:
-
欢迎来到 SO。请edit 并将任何代码/错误/输出粘贴为文本。见:Why not upload images of code/errors when asking a question?
-
图片不代表代码。没有一个
print。创建minimal reproducible example。 -
@MarkTolonen 你的意思是像工作代码吗?喜欢我现在得到的完整的吗?
-
是的,工作脚本,如果可能的话,简化为只关注问题。描述实际与期望的行为。阅读minimal reproducible example 链接。
-
@tdelaney 我添加了完整代码
标签: python-3.x