Lab 3

Description:
This is a program that asks the user to select an option from the menu and to input a value for both x and y. After they input the values, they will get the result of whatever option they chose from the menu. If they choose “Add”, the program will add the two values; if they choose “Subtract”, the program will subtract the two values, etc.

Code:

menu = True
while menu:
    print("""
    1. Add
    2. Subtract
    3. Multiply
    4. Divide
    5. Remainder
    6. Compare
    7. Exit""")
    choice = input("Choose an option")
    if choice == 1:
        x = int(input("Enter a value for x"))
        y = int(input("Enter a value for y"))
        print(x + y)
    elif choice == 2:
        x = int(input("Enter a value for x"))
        y = int(input("Enter a value for y"))
        print(x - y)
    elif choice == 3:
        x = int(input("Enter a value for x"))
        y = int(input("Enter a value for y"))
        print(x * y)
    elif choice == 4:
        x = int(input("Enter a value for x"))
        y = int(input("Enter a value for y"))
        print(x / y)
    elif choice == 5:
        x = int(input("Enter a value for x"))
        y = int(input("Enter a value for y"))
        print(x % y)
    elif choice == 6:
        x = int(input("Enter a value for x"))
        y = int(input("Enter a value for y"))
        if(x  y):
            print('x is greater than y')
        elif(x == y):
            print('x is equal to y')
    elif choice == 7:
        menu = False


Screenshot:
lab3

Leave a Reply

Your email address will not be published. Required fields are marked *