为什么骰子滚动模拟器需要两个函数?

时间:2018-05-30 14:32:29

标签: python-3.x random dice

我做了一个简单的骰子滚动模拟器,但之后,在查看其他人的例子时,他们通常创建了两个函数(Main用于定义范围1 - 6,以及roll_dice功能)。我完成了它可以吗?对我来说,其他版本似乎更复杂(例如使用while循环),没有任何额外的功能。

我的代码:

import random

def roll_dice():
    for x in range(1):
        print("You rolled a", (random.randint(1, 6)),"!")
        roll_again = input("Would you like to roll again? (Y or N): ")
        if roll_again.lower() == "y":
        roll_dice()
        if roll_again.lower() == "n":
            print("Thanks for rolling. See you next time")
        else:
            roll_again = input("Would you like to roll again? (Y or N): ")

谢谢!

0 个答案:

没有答案