177k views
0 votes
Write a program that asks user to enter three number and find the largest number using FUNCTION..... END FUNCTION and smallest using SUB....END SUB.​

User Shitu
by
7.2k points

1 Answer

1 vote

Answer:

My brother taught me about programming soo...

Step-by-step explanation:

# Function to find the largest number

def find_largest(a, b, c):

return max(a, b, c)

# Sub-routine to find the smallest number

def find_smallest(a, b, c):

smallest = a

if b < smallest:

smallest = b

if c < smallest:

smallest = c

return smallest

# Main program

num1 = int(input("Enter the first number: "))

num2 = int(input("Enter the second number: "))

num3 = int(input("Enter the third number: "))

largest = find_largest(num1, num2, num3)

smallest = find_smallest(num1, num2, num3)

print("The largest number is:", largest)

print("The smallest number is:", smallest)

In this program, we define a function called find_largest that takes three parameters (a, b, c) and uses the max() function to find the largest number among them. We also define a sub-routine called find_smallest that takes the same three parameters (a, b, c) and compares them using conditional statements to find the smallest number. Finally, in the main program, we prompt the user to enter three numbers, call the functions/sub-routines, and print the largest and smallest numbers.

User Matt Mills
by
8.9k points

No related questions found