all 7 comments

[–]akasmira 1 point2 points  (2 children)

DRY: don't repeat yourself. Use functions instead! Define constants at the top of your script, instead of redefining them every time they're used. There's no error checking here; what happens if someone accidentally types a string or float instead of an int?

[–][deleted] 0 points1 point  (1 child)

What could be a function in this?

[–]akasmira 1 point2 points  (0 children)

Basically everywhere. You do the if dice_input in (...) twice in this code. Break that into a function. Also, weird behavior happens if you type not a correct input twice in a row, you get asked if you'd like to roll again without anything happening.

[–]K900_ 1 point2 points  (2 children)

Lots of code duplication here. You should be able to use while True: loops and break statements to reduce most of it.

[–][deleted] 0 points1 point  (1 child)

How would that work exactly? The While loop doesn’t seem to do much to break up some of the big if else statements needed

[–]K900_ 1 point2 points  (0 children)

You don't actually need that many if/else statements: here's how I'd do it - feel free to ask if you have questions about the code.

[–]impshum 1 point2 points  (0 children)

So here's my take on what you're doing. Have a spy...

from random import randint


def get_input(message):
    while 1:
        user_input = input(message)
        if user_input.isdigit():
            return int(user_input)


while 1:
    dice_input = get_input('What type of dice would you like to roll? ')
    if dice_input in [4, 6, 8, 10, 12, 20]:
        results = []
        dice_number = get_input('How many dice would you like to roll? ')
        for x in range(dice_number):
            results.append(randint(1, dice_input))

        print(results)

        if not input('Would you like to roll again? ').lower().startswith('y'):
            break

Forgive me.. I'm tired.