Skip to content

Commit 57586ff

Browse files
committed
......
1 parent 39d339e commit 57586ff

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

85.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,49 @@
1-
# An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of numbers which have been given to you. The rest of the given series is the same as the original AP. Find the missing term.
1+
inpf = open('input4.txt', 'r')
2+
outf = open('output4.txt', 'w')
3+
val1 = inpf.readlines()
4+
id = val1[1].split()
5+
marks = val1[2].split()
6+
num_lst = []
7+
val_lst = []
8+
dct = {}
9+
for i in range(len(marks)):
10+
if int(marks[i]) not in dct.keys():
11+
num_lst.append(int(marks[i]))
12+
val_lst.append(int(id[i]))
13+
dct[int(marks[i])] = [id[i]]
14+
else:
15+
dct[int(marks[i])].append(id[i])
16+
val_lst.append(int(id[i]))
217

3-
# You have to write a function that receives a list, list size will always be at least 3 numbers. The missing term will never be the first or last one.
4-
#find_missing([1, 3, 5, 9, 11]) == 7
18+
#for descending
19+
for p in range(len(num_lst)):
20+
max_indx = p
21+
for q in range(p+1, len(num_lst)):
22+
if num_lst[q] > num_lst[max_indx]:
23+
max_indx = q
24+
if max_indx != p:
25+
temp = num_lst[p]
26+
num_lst[p] = num_lst[max_indx]
27+
num_lst[max_indx] = temp
28+
29+
#for ascending
30+
def selection(val_lst):
31+
for u in range(len(val_lst)):
32+
min_indx = u
33+
for v in range(u+1, len(val_lst)):
34+
if val_lst[v] < val_lst[min_indx]:
35+
min_indx = v
36+
if min_indx != u:
37+
temp = val_lst[u]
38+
val_lst[u] = val_lst[min_indx]
39+
val_lst[min_indx] = temp
40+
return val_lst
41+
42+
43+
for k in num_lst:
44+
for l in selection(dct[k]):
45+
outf.write(f'ID {l} Mark: {k}\n')
46+
inpf.close()
547

648

749

0 commit comments

Comments
 (0)