Lab 2

Lab Description:

In this lab we used python script to write a program that displays a menu to the user with the option, such as (1) enter a number and (2) exit. After that we wrote programs that performs operations such as the sum x + y, the difference x – y, the product x * y, the quotient x/y, the remainder x%y, and whether x is less than, equal, or greater than y. Finally when we run the script in python and entered option 1, the program ask for an integer for x and an integer for y and displayed the results of all the operations.

Code:

option=input("select an option(1) enter a number and (2) exit ")
#print (option)
o = int(option)
if (o == 1):
    x=input("enter value x")
    xint = int(x)
    y=input("enter value y")
    yint = int(y)
    z=xint+yint
    print ("x+y= ", z)
    z=xint-yint
    print ("x-y= ", z)
    z=xint*yint
    print ("x*y= ", z)
    z=xint/yint
    print ("x/y= ", z)
    z=xint%yint
    print ("x%y= ", z)
    if xinty:
        print ('x is greater than y')
    else:
        print ('x and y are equal')

Screenshot:

Capture

Leave a Reply

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