Ask Question
11 March, 22:28

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. 11 March, 22:32
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers