哪个数字更大以及随机数是多少

Which number is bigger and by how much for random numbers

我正在做一个关于 python 的在线教程,它要求编写一个程序,将两个随机整数作为参数,并使用 void 函数显示哪个整数较大以及增大了多少。但是,如果两个随机 intgars 相同,那么 def show-larger 也应该处理这个问题。因此,在主要部分中,我编写了生成 2 个随机数的代码,我不确定如何进行下一步并使用整数作为参数调用 show_larger。给出的示例解决方案是 3 比 1 大 2 并且整数相等,均为 3。 这是我目前所拥有的:

def main():
value_1=random.randrange(1,6)
value_2=random.rangrange(1,6)

def show_larger():    
difference= value_1=-value_2
if value_1 == value_2:
    print('The integers are equal, both are' + str(value_1))

这将是一种简单的方法。

import random

def main():
    value_1=random.randrange(1,6)
    value_2=random.randrange(1,6)
    show_larger(value_1, value_2)

def show_larger(value_1, value_2):
    if value_1 == value_2:
        print('The integers are equal, both are' + str(value_1))
        return
    else:
        print(("value_1" if value_1>value_2 else "value_2") + "is bigger by" + str(abs(value_1 - value_2)))

main()