1# Note: The last time I tested something was missing so I couldn't work
2import pathlib
3import transpyle
4
5path = pathlib.Path('my_script.py')
6code_reader = transpyle.CodeReader()
7code = code_reader.read_file(path)
8
9from_language = transpyle.Language.find('Python 3.6')
10to_language = transpyle.Language.find('Fortran 95')
11translator = transpyle.AutoTranslator(from_language, to_language)
12fortran_code = translator.translate(code, path)
13print(fortran_code)
14
1def activity_selection(a, s, f, n):
2 A = [0]*n
3 A[1] = a[1]
4
5 k=1
6 iter = 1
7
8 for i in range(2, n+1):
9 if(s[i] >= f[k]):
10 #appending list A
11 iter = iter+1
12 A[iter] = a[i]
13 k=i
14
15 '''
16 Making first element of the list A (index 0) equal to iter
17 just to know the length of the list when used in different function.
18 '''
19 A[0] = iter;
20 return A
21
22if __name__ == '__main__':
23 #Lists staring from 1. Elements at index 0 are fake
24 a = [0, 2, 3, 5, 1, 4]
25 s = [0, 0, 1, 3, 4, 1]
26 f = [0, 2, 3, 4, 6, 6]
27 p = activity_selection(a, s, f, 5)
28
29 #p[0] is the length upto which activities are stored
30 for i in range(1, p[0]+1):
31 print(p[i])