用Python分析函数单调性

写程序自动分析下面函数在(0,2]区间上的单调性 y=-x-ln(x)

import random
import math


def f(x):
    # return x
    # return -x
    return -x - math.log(x)


data, sort1, sort2, sort3 = [], [], [], []
while len(data) != 10:  # 随机生成10个x数区间是(0,2]
    random_ = random.random() * 1000 % 200 / 100
    if random_ != 0:
        data.append((random_, f(random_)))
sort1.extend(data)
sort1.sort(key=lambda x: x[0])  # 按x值升序排
sort2.extend(data)
sort2.sort(key=lambda x: x[1])  # 按y值升序排
sort3.extend(data)
sort3.sort(key=lambda x: x[1], reverse=True)  # 按y值降序排
if sort1 == sort2:  # 两个排序的结果一样则是单调函数
    print("单调递增函数")
elif sort1 == sort3:
    print("单调递减函数")
else:
    print("非单调函数")