usr bin python2 from os import system from sys import exit from comman

 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
#!/usr/bin/python2.5
from os import system
from sys import exit
from commands import getoutput
MAXIMA_COMMAND = u'/usr/bin/maxima --batch-string="string(%s);" --very-quiet'
INFILE = u'task.in'
OUTFILE = u'task.out'
if "__main__" == __name__:
try:
fin = open(INFILE, "r")
fout = open(OUTFILE, "w")
except IOError, e:
sys.exit(u'error: %s' % e)
task = []
for line in fin:
task.append(line.strip())
if 0 == len(task) % 2:
answer = getoutput(MAXIMA_COMMAND % (task[0])).split("\n")[1].strip()
value = getoutput(MAXIMA_COMMAND % (answer.replace(u'x', str(float(task[1]))))).split("\n")[1].strip()
print (MAXIMA_COMMAND % (answer.replace(u'x', str(float(task[1])))))
fout.write(u'%s\n%s\n' % (answer, value))
fout.write(u'%s\n%s\n' % (answer, value))
task = []
fin.close()
fout.close()
task.in:
diff(cos(x), x)
1
diff(sin(x)*cos(x), x)
3