Dice rolling simulator, any ideas on implementing any features?
I normally would agree with Graipher here, however with your code I think there's a simpler and more readable solution.


The first number doesn't have to be larger than the second.

This is an artificial limitation that can be fixed by sorting the inputted values.
Not allowing the same value to be selected is an artificial limitation. random.randint includes both bounds, meaning random.randint(n, n) is valid input.
You can bundle the first two try statements together to simplify the code.

This makes the code DRY as the two loops are logically doing two different things.


Whilst longer it keeps the functionality to change the lower bound if you enter it incorrectly, without having to kill the process.

import random

while True:
    try:
        min_, max_ = sorted([
            int(input("Please enter one of the bounds: "))
            int(input("Please enter the other bound: "))
        ])
        break
    except ValueError:
        print("Invalid input")

while True:
    try:
        amount = int(input("How many times do you want to roll the dice: "))
        break
    except ValueError:
        print("Invalid input")

for _ in range(amount):
    print(random.randint(min_, max_))


Note: You can move both the while try loops into a function, and pass a lambda, however I don't think that's as readable.

min_, max_ = while_try(lambda: sorted([
    int(input("Please enter one of the bounds: "))
    int(input("Please enter the other bound: "))
]))