Write a 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.

EXAMPLE OUTPUT 1
3 is larger than 1 by 2
EXAMPLE OUTPUT 2
The integers are equal, both are 3


Answer:

The code is given below
import random
def show_larger(a,b):
if a==b:
print("The integers are equal, both are",a);
elif a>b:
print(a,'is larger than',b,'by',a-b)
else:
print(b,'is larger than',a,'by',b-a)
a=random.randint(1,5)
b=random.randint(1,5)
show_larger(a,b)

Computer Science & Information Technology

You might also like to view...

The data security manage function is geared around ____ creation and enforcement.

A. procedure B. policy C. standard D. resource

Computer Science & Information Technology

When an element is displayed in the exact specified position, ____ positioning is used.

A. default B. relative C. absolute D. center

Computer Science & Information Technology

When you are working with a specific function, such as a table, ________ tabs appear on the Ribbon

A) contextual B) complementary C) custom D) specified

Computer Science & Information Technology

Ruby's built-in language looping constructions include which of the following?

A. while B. until C. for D. All of the above

Computer Science & Information Technology