Write an algorithm, draw corresponding flow chart and write an interactive program which prompts the user with the following options on the opening menu: (15) 1) To accept two integers and check whether they are equal or not 2) To check whether a given number is even or odd 3) To check whether a given number is a positive number or a negative number 4) Quit

, , No Comments

 Certainly! Below is an algorithm, corresponding flowchart, and an example interactive program in Python that implements the described menu:


 Algorithm:


1. Display the menu options.

2. Prompt the user to choose an option.

3. If the user chooses option 1, accept two integers, compare them, and display whether they are equal or not.

4. If the user chooses option 2, accept a number, check if it's even or odd, and display the result.

5. If the user chooses option 3, accept a number, check if it's positive or negative, and display the result.

6. If the user chooses option 4, exit the program.

7. If the user enters an invalid option, display an error message.

8. Repeat the process until the user chooses to quit.


 Flowchart:


![Flowchart](https://i.imgur.com/22cp3VO.png)


 Interactive Program in Python:


```python

def check_equality():

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

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

    

    if num1 == num2:

        print("The integers are equal.")

    else:

        print("The integers are not equal.")


def check_even_odd():

    num = int(input("Enter a number: "))

    

    if num % 2 == 0:

        print("The number is even.")

    else:

        print("The number is odd.")


def check_positive_negative():

    num = int(input("Enter a number: "))

    

    if num > 0:

        print("The number is positive.")

    elif num < 0:

        print("The number is negative.")

    else:

        print("The number is zero.")


Main menu loop

while True:

    print("\nMenu:")

    print("1) Check equality of two integers")

    print("2) Check even or odd")

    print("3) Check positive or negative")

    print("4) Quit")


    choice = input("Enter your choice (1-4): ")


    if choice == '1':

        check_equality()

    elif choice == '2':

        check_even_odd()

    elif choice == '3':

        check_positive_negative()

    elif choice == '4':

        print("Exiting the program. Goodbye!")

        break

    else:

        print("Invalid choice. Please enter a number from 1 to 4.")

```


This program allows the user to choose from the menu options and performs the corresponding operations. It will continue to run until the user chooses option 4 to quit.

0 टिप्पणियाँ:

Post a Comment