0% found this document useful (0 votes)
26 views4 pages

SC 1

The document contains a Python program that performs Cartesian product and maxmin/minmax composition of two sets or relations. It prompts the user to input elements for two sets or relations and calculates the Cartesian product or compositions based on user choices. The program continues to run until the user decides to exit.

Uploaded by

bgischampion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

SC 1

The document contains a Python program that performs Cartesian product and maxmin/minmax composition of two sets or relations. It prompts the user to input elements for two sets or relations and calculates the Cartesian product or compositions based on user choices. The program continues to run until the user decides to exit.

Uploaded by

bgischampion
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name - Avinash Parchake

Roll no- 23

#Cartesian product and maxmin composition


def cartesian():
n = int(input("\nEnter number of elements in first set (A): "))
A = []
B = []
print("Enter elements for A:")
for i in range(0, n):
ele = float(input())
A.append(ele)
m = int(input("\nEnter number of elements in second set (B): "))
print("Enter elements for B:")
for i in range(0, m):
ele = float(input())
B.append(ele)
print("A = {"+str(A)[1:-1]+"}")
print("B = {"+str(B)[1:-1]+"}")
cart_prod = []
cart_prod = [[0 for j in range(m)]for i in range(n)]
for i in range(n):
for j in range(m):
cart_prod[i][j] = (A[i]*B[j])
print("A x B = ")
for i in range(n):
for j in range(m):
print((round(cart_prod[i][j], 2)),end=" ")
print("\n")
return

def minmax():
r1 = int(input("Enter number of rows of first relation (R1): "))
c1 = int(input("Enter number of columns of first relation (R1): "))
rel1=[[0 for i in range(c1)]for j in range(r1)]
print("Enter the elments for R:")
for i in range(r1):
for j in range(c1):
rel1[i][j]=float(input())

r2 = int(input("Enter number of rows of second relation (R2): "))


c2 = int(input("Enter number of columns of second relation (R2):
"))
rel2=[[0 for i in range(c2)]for j in range(r2)]
print("Enter the elments for R:")
for i in range(r2):
for j in range(c2):
rel2[i][j]=float(input())

print("\nR1 = ")
for i in range(r1):
for j in range(c1):
print(rel1[i][j],end=" ")
print("\n")
print("\nR2 = ")
for i in range(r2):
for j in range(c2):
print(rel2[i][j],end=" ")
print("\n")

col=0
comp=[]
for i in range(r1):
comp.append([])
for j in range(c2):
l=[]
for k in range(r2):
l.append(max(rel1[i][k],rel2[k][j]))
comp[i].append(min(l))

print("\nR1 composition R2 =")


for i in range(r1):
for j in range(c2):
print(comp[i][j],end=" ")
print("\n")
return

def maxmin():
r1 = int(input("Enter number of rows of first relation (R1): "))
c1 = int(input("Enter number of columns of first relation (R1): "))
rel1=[[0 for i in range(c1)]for j in range(r1)]
print("Enter the elments for R:")
for i in range(r1):
for j in range(c1):
rel1[i][j]=float(input())

r2 = int(input("Enter number of rows of second relation (R2): "))


c2 = int(input("Enter number of columns of second relation (R2):
"))
rel2=[[0 for i in range(c2)]for j in range(r2)]
print("Enter the elments for R:")
for i in range(r2):
for j in range(c2):
rel2[i][j]=float(input())

print("\nR1 = ")
for i in range(r1):
for j in range(c1):
print(rel1[i][j],end=" ")
print("\n")
print("\nR2 = ")
for i in range(r2):
for j in range(c2):
print(rel2[i][j],end=" ")
print("\n")

col=0
comp=[]
for i in range(r1):
comp.append([])
for j in range(c2):
l=[]
for k in range(r2):
l.append(min(rel1[i][k],rel2[k][j]))
comp[i].append(max(l))

print("\nR1 composition R2 =")


for i in range(r1):
for j in range(c2):
print(comp[i][j],end=" ")
print("\n")
return

ch=1
while ch==1:
print("MENU:\n----\n1->Cartesian Product\n2->maxmin Composition\n3-
>minmax Composition\n4->Exit")
op=int(input("Enter Your Choice: "))
if op==1:
cartesian()
elif op==2:
maxmin()
elif op==3:
minmax()
elif op==4:
break
else:
print("Wrong Choice!")
ch=int(input("Do you wish to continue (1-Yes | 0-No): "))
print("\n")

Output:
MENU:
----
1->Cartesian Product
2->maxmin Composition
3->minmax Composition
4->Exit
Enter Your Choice: 1

Enter number of elements in first set (A): 4


Enter elements for A:
0.7
0.5
0.8
0.4

Enter number of elements in second set (B): 6


Enter elements for B:
0.9
0.6
0.2
0.1
0.7
0.5
A = {0.7, 0.5, 0.8, 0.4}
B = {0.9, 0.6, 0.2, 0.1, 0.7, 0.5}
A x B =
0.63 0.42 0.14 0.07 0.49 0.35

0.45 0.3 0.1 0.05 0.35 0.25

0.72 0.48 0.16 0.08 0.56 0.4

0.36 0.24 0.08 0.04 0.28 0.2

Do you wish to continue (1-Yes | 0-No): 1

MENU:
----
1->Cartesian Product
2->maxmin Composition
3->minmax Composition
4->Exit
Enter Your Choice: 2
Enter number of rows of first relation (R1): 2
Enter number of columns of first relation (R1): 2
Enter the elments for R:
0.7
0.5
0.8
0.4
Enter number of rows of second relation (R2): 2
Enter number of columns of second relation (R2): 3
Enter the elments for R:
0.9
0.6
0.2
0.1
0.7
0.5

R1 =
0.7 0.5

0.8 0.4

R2 =
0.9 0.6 0.2

0.1 0.7 0.5

R1 composition R2 =
0.7 0.6 0.5

0.8 0.6 0.4

Do you wish to continue (1-Yes | 0-No): 0

You might also like