mercredi 30 mai 2018

Why do I need two functions for dice rolling simulator?

I've made a simply dice rolling simulator but afterwards, when looking at other people's examples, they've generally created two functions (Main to define the range 1 - 6, and a roll_dice function). Is it ok as I've done it? To me, the other versions seem more complex (with a while loop for example) without any extra functionality.

My code:

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): ")

Thanks!




Aucun commentaire:

Enregistrer un commentaire