Lab #3

Description

Lab 3 was very similar to lab two. The only difference is that now we will bu utilizing functions. We set up the integers and all by using functions. Once this is done, we go through the same procedure as lab 2. Now that we are implementing functions, the user has 6 arithmetic choices. He/she can select any integers and get different results. When they are done they just press #7 to finish.

Coding

def add(x, y):
    j = x+y
    return j
def subtract (x, y):
    a = x-y
    return a
def multiply (x, y):
   k = x*y
   return k
def divide(x, y):
    e = x/y
    return e
def remainder(x, y):
    z = x%y
    return z
dog = True
while dog == True:
    option = input ("Hi, how may I help you? 1).Add 2).Subtract 3).Multiply 4).Divivde 5).Find Remainder 6).Compare 7).Exit")
    if option == 7:
        print "Thank you, come again!"
        break
    if option == 1:
        x = input ("Select value of x ")
        y = input ("Select value of y ")
        print add(x, y)
    if option == 2:
        x = input ("Select value of x ")
        y = input ("Select value of y ")
        print subtract(x, y)
    if option == 3:
        x = input ("Select value of x ")
        y = input ("Select value of y ")
        print multiply(x ,y)
    if option == 4:
        x = input ("Select value of x ")
        y = input ("Select value of y ")
        print divide(x, y)
    if option == 5:
        x = input ("Select value of x ")
        y = input ("Select value of y ")
        print remainder(x, y)
    if option == 6:
        x = input ("Select value of x ")
        y = input ("Select value of y ")
        if x>y:
            print ("X is greater than Y")
        if x<y:
            print ("X is less than Y")
        if x==y:
            print ("X is equal to Y")

 

Screen Shots!

Lab3 run

 

Leave a Reply

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