Write a python program that contains a main function and a custom, void function named show_larger that takes two random integers as parameters. This function should display which integer is larger and by how much. The difference must be expressed as a positive number if the random integers differ. If the random integers are the same, show_larger should handle that, too. See example outputs. In the main function, generate two random integers both in the range from 1 to 5 inclusive, and call show_larger with the integers as arguments.

Respuesta :

def show_larger(n1,n2):
if n1>n2:
print(str(n1)+" is larger than "+str(n2)+" by "+str(n1-n2))
elif n2>n1:
print(str(n2)+" is larger than "+str(n1)+" by "+str(n2-n1))
else:
print(str(n2)+" is same as "+str(n1))
import random
def main():
n1 = random.randint(1, 5)
n2 = random.randint(1, 5)
show_larger(n1,n2)

main()