UNION INTERSECTION COMPLEMENT SET DIFFERENCE OF DICTIONARIES IN PYTHON

UNION INTERSECTION COMPLEMENT SET DIFFERENCE OF DICTIONARIES IN PYTHON

def inp(n):
    d1={}
    print("Enter for Fuzzy set")
    for i in range(n):
        key= input("Enter key value: ")
        value= float(input("Enter value for key : "))
        d1[key]=value
    return d1

def ui():
    d1={}
    d2={}
    d3={}
    d4={}
    n=int(input("Enter the limit: "))
    print("Enter for First Fuzzy set")
    d1=inp(n)
    
    
    print("Enter for second Fuzzy set")
    d2=inp(n)
    for (x,y), (x2,y2) in zip(d1.items(), d2.items()):
        if y > y2:
            d3[x]=y
        else:
            d3[x]=y2
    print("The Fuzzy set is: ",d1)
    print("The Fuzzy set is: ",d2)
    print("Union of two dict is ",d3)
    for (x,y), (x2,y2) in zip(d1.items(), d2.items()):
        if y < y2:
            d4[x]=y
        else:
            d4[x]=y2
    print("Intersection of two dict is ",d4)

def com():
    d1=dict()
    y=dict()
    n=int(input("Enter the limit: "))
    print("Enter for First Fuzzy set")
    for i in range(n):
        key= input("Enter key value: ")
        value= float(input("Enter value for key : "))
        d1[key]=value
        y[key] = str(1-value)
    print("\nThe Fuzzy set is: ",d1)
    print("PRINT THE FUZZY COMPLEMENT SET: ",y)

# // a1 0.4 a2 0.7 a3 0.3 a4 0.6


def seD():
    d1={}
    d2={}
    y={}
    n=int(input("Enter the limit: "))
    print("Enter for First Fuzzy set")
    d1=inp(n)
    
    print("Enter for second Fuzzy set")
    d2=inp(n)

    for d1_key, d2_key in zip(d1,d2):
        d1_value=d1[d1_key]
        d2_value=d2[d2_key]
        d2_value= 1 - d2_value
        if d1_value < d2_value:
            y[d1_key]=d1_value
        else:
            y[d2_key]=d2_value

    print("The Fuzzy set is: ",d1)
    print("The Fuzzy set is: ",d2)
    print("SET DIFFERENCE OF D1 and D2 is ",y)




ch=int(input("1. Union Intersection, 2. Complement, 3. Set Difference, 4. Associative\nEnter choice: "))
if ch==1:
    ui()
elif ch==2:
    com()
elif ch==3:
    seD()
else:
    print("Try again")    



Comments

Popular posts from this blog

PYTHON TRINKET

FOR LOOP WITH ZIP FUNCTION IN PYTHON

Tuple