Ask Question
7 November, 16:34

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.

+4
Answers (1)
  1. 7 November, 19:12
    0
    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 ()
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a python program that contains a main function and a custom, void function named show_larger that takes two random integers as ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers