-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello.py
45 lines (35 loc) · 1.17 KB
/
hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
gm = [[0,1,1,1,0],
[1,0,0,1,0],
[1,0,0,0,1],
[1,1,0,0,0],
[0,0,1,0,0]]
temp1 = []
temp2 = []
p1 = int(input('Please enter first persons index : '))
p2 = int(input('Please enter second persons index : '))
def checkPersonOne(): #check if 'p2' is a friend of 'p1'
if gm[p1][p2] == 1:
return True
def checkPersonTwo(): #check if 'p1' is a friend of 'p2'
if gm[p2][p1] == 1:
return True
def checkBoth(): #check if above condition is valid
first = checkPersonOne()
second = checkPersonTwo()
if first and second == True:
print("Direct friends")
else:
for i in gm[p2]: #check if person two has friends
if i == 1:
index1 = gm[p2].index(i)
temp1.append(index1)
for j in gm[p1]: #check if person one has friends
if j == 1:
index2 = gm[p1].index(j)
temp2.append(index2)
commonList = list(set(temp1) and set(temp2)) #check for the common friends
if 1 in commonList:
print('found a friend in common')
else:
print('no such friend in common')
checkBoth();