Knowee
Questions
Features
Study Tools

Write a program to display a menu driven facility to find the greatest of two numbers,three numbers and four numbers

Question

Write a program to display a menu driven facility to find the greatest of two numbers,three numbers and four numbers

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a simple Python program that provides a menu-driven facility to find the greatest of two, three, and four numbers.

def find_greatest(numbers):
    return max(numbers)

while True:
    print("\nMenu")
    print("1. Find greatest of two numbers")
    print("2. Find greatest of three numbers")
    print("3. Find greatest of four numbers")
    print("4. Exit")

    choice = int(input("Enter your choice: "))

    if choice == 1:
        num1 = int(input("Enter first number: "))
        num2 = int(input("Enter second number: "))
        print("Greatest number is", find_greatest([num1, num2]))
    elif choice == 2:
        num1 = int(input("Enter first number: "))
        num2 = int(input("Enter second number: "))
        num3 = int(input("Enter third number: "))
        print("Greatest number is", find_greatest([num1, num2, num3]))
    elif choice == 3:
        num1 = int(input("Enter first number: "))
        num2 = int(input("Enter second number: "))
        num3 = int(input("Enter third number: "))
        num4 = int(input("Enter fourth number: "))
        print("Greatest number is", find_greatest([num1, num2, num3, num4]))
    elif choice == 4:
        break
    else:
        print("Invalid choice. Please choose a valid option.")

This program first defines a function find_greatest that takes a list of numbers and returns the maximum number. It then enters a loop where it displays a menu to the user and asks for their choice. Depending on the user's choice, it asks for the appropriate number of inputs, finds the greatest number using the find_greatest function, and prints the result. If the user chooses to exit, it breaks out of the loop. If the user enters an invalid choice, it prints an error message and continues with the next iteration of the loop.

This problem has been solved

Similar Questions

Develop a Java program to identify the largest among four numbers (32, 29,34, 21) using appropriate control statement and operators.

Accept three numbers from the user and display the second largest number.

Problem Statement:Write a program to accept 4 numbers as input and sequence them in the descending order. You may assume that the numbers will not be equal.Input Format:Four space separated Integers - num1, num2, num3 and num4.Output Format:Display the four integers in the decreasing order - integer>integer>integer>integerConstraints1<=num<=2,147,483,647Sample Input 16789 6790 6788 6787Sample Output 16790>6789>6788>6787Sample Input 20 1 2 3Sample Output 23>2>1>0

Write a program with a generic function that will sort array of integer, float value. The program should have a menu with appropriate options and accept the values from the user

Construct a Pseudocode to take three numbers and print largest and smallest among them.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.