mardi 27 juillet 2021

Issues with IF repeating loops

To preface, I'm very new to coding with python and coding period. I've made a dice roller in python which allows the user to decide the number of sides, as well as the number of dice rolled. The code works as intended, but I keep getting an error message whenever I do multiple re-rolls and exit out. I've posted a screenshot of the error message and copied over the code too. I'd really appreciate any feedback, and thanks for reading this far. Error Message

## Roller v2

def Roll2():
    print("""
    [ - - - Welcome to Roller v2! - - - ]
    """)
    sides = int(input("How many sides? : "))
    dice = int(input("How many dice? : "))
    modifier = input("Any Modifiers (Include +/-) : ")

    def roller():
        import random as rand
        from random import choices
        d_inf = range(1, sides+1)
        d_choice = choices(d_inf, k=dice)
        print("""Wowee, you rolled :
        """)
        print(d_choice)
        print(""" """)
        print("Unadded Modifiers : (" + modifier + ")")

        repeat = str(input("Would you like to roll the same dice again? (y/n) : "))

        if repeat in ["y", "Y"]:
            roller()
        elif repeat in ["n", "N"]:
            exit = str(input("Would you like to exit? (y/n) : "))
        
        if exit in ["y", "Y"]:
            print("Goodbye!\n")
        elif exit in ["n", "N"]:
            Roll2()
  
    roller()



Aucun commentaire:

Enregistrer un commentaire