闲来无趣,用Python写了个小东西。写得有点丑,运行时自己改变量,自动生成阿三哥的问答题答案
Python中的双引号和单引号一般情况下没有区别,所以中间各种混用。因为C程序员通常喜欢双引号表示字符串~~~
import string
count_tf = 30
count_mc = 40
count_cp = 25
fin = open("charpter4.in", "r");
fout = open("charpter4.out", "w");
#True/False Part
fout.write("True/False Part\n")
count = 0;
while count < count_tf:
count = count + 1
line = fin.readline()
index = line.find('*a. True', len(line) - 10)
line = fin.readline()
fout.write(str(count) + ". ")
if index == -1:
fout.write("False\n");
else:
fout.write("True\n");
fout.write("\n\n")
#Multiple Choice part
fout.write("Multiple Choice Part\n")
count = 0
while count < count_mc:
count = count + 1;
temp = 0
while temp < 5:
temp = temp + 1;
line = fin.readline()
index = line.find('\t')
if index >= 0:
#print "find"
#print line[index + 1:]
fout.write(str(count) + ". ")
fout.write(line[index + 1: index + 2] + "\n")
fout.write("\n\n")
#COMPLETION Part
fout.write("Completion Part\n")
count = 0
line = fin.readline()
while count < count_cp:
count = count + 1
line = fin.readline()
#print 'out:' + line
fout.write(str(count) + ". ")
fout.write(line[3:])
x = 'bcd'
line = fin.readline()
for c in x:
s = c + '. '
#print s
if line.find(s, 0, 5) >= 0:
line = fin.readline()
#print line
if not line:
break
#Need for charpter 4
line = fin.readline()
fin.close()
fout.close()