Lab 3

Description:

In lab number 3 we had to write the program that will interact with user. Program have to give user option to do different math calculations. User have to choose calculation hey want then they have to put numbers they want to do certain calculation with. User can repeat this process as many times until decides to exit.

Code:

 

c = 1
while c < 2:
    option = input (" Press: (1) Sum numbers, (2) Subtract numbers, (3) Multiply numbers, (4) Divide numbers, (5) Remainder of numbers, (6) Compare numbers, (7) Exit ")
    if option == 1:
       x = input (' Enter number for x:')
       y = input (' Enter number for y:')
       print ('The sum of x and y is:', x+y)
    if option == 2:
        x = input (' Enter number for x:')
        y = input (' Enter number for x:')
        print (' The difference of x and y is:', x-y)
        print (' The difference of y and x is:', y-x)
    if option == 3:
        x = input (' Enter number for x:')
        y = input (' Enter number for y:')
        print (' The result of x and y is:', x*y)
    if option == 4:
        x = input (' Enter number for x:')
        y = input (' Enter number for x:')
        print (' The quotient of x and y is:', float(x) / float(y) )
        print (' The quotient of y and x is:', float(y) / float(x) )
    if option == 5:
        x = input (' Enter number for x:')
        y = input (' enter number for y:')
        print (' The remainder of x from y is:', y%x)
        print (' The remainder of y from x is:', x%y)
    if option == 6:
        x = input (' Enter number for x:')
        y = input (' Enter number for y:')
        if x < y:
            print ('x is less than y')
        if x == y:
            print ('x is equal to y')
        else:
            print ('x is greater than y')
    if option == 7:
        c = c + 5

Screen shots:

lab-1

lab-2

 

Leave a Reply

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