samedi 10 mars 2018

Python function with a unassigned variable

I'm currently working on a flask and python app: https://getanumber.herokuapp.com/

When you click on generate without value, an Internal Server Error appears.

I would like to print a message when this happen. Here what I got so far but it doesn't work:

def RandomNumberGenerator():
    import random
    Min = request.form['Min']
    Max = request.form['Max']
    xMin = int(Min)
    xMax = int(Max)
    if xMin > xMax:
        return "Min value can not be higher than max value"
    elif xMin is None:
        return "Precise the min value"
    elif xMax is None:
        return "Precise the max value"
    else:
        return str(random.randint(xMin, xMax))

BR




Aucun commentaire:

Enregistrer un commentaire