Ask Question
23 November, 10:46

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.

+2
Answers (1)
  1. 23 November, 10:52
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers