我的程序应该为每一个骰子显示一对骰子,这是按计划进行的。我想它重复多次,但每次重复它不再是随机的,只是重复从第2行和第3行分配的数字。如果我掷2和3,它每次都重复2和3。 如何使它每次循环时都分配一个新的随机数?你知道吗
import random
dice1 = random.randrange(1,6)
dice2 = random.randrange(1,6)
。。。[编辑:]
visualdice_1 =( """
+-------+
| |
| * |
| |
+-------+""")
visualdice_2 =( """
+-------+
| * |
| |
| * |
+-------+""")
然后与
def showdice():
#Dice1 Visual Execution
if dice1 == 1:
print(visualdice_1)
if dice1 == 2:
print(visualdice_2)
def start():
confirmation = input("Would you like to roll the dice? (Y/N): ")
if confirmation == "Y" or confirmation == "y":
print ("You've rolled:",dice1,"and", dice2), showdice()
return start()
else:
print("Goodbye")
start()
只需重新运行:
在打印功能之前。你知道吗
您在描述中发现了自己的问题:“第2行和第3行的指定号码”。在循环上方指定数字。你知道吗
相反,将随机数生成器放入循环中,并编辑
showdice()
函数,将骰子值作为参数:否则,它将始终使用与您在脚本顶部实例化的相同的随机掷骰子。你知道吗
相关问题 更多 >
编程相关推荐