Python解析项目管理问题和答案

本文展示了一个使用Python实现的功能,能够自动生成阿三哥的问答题答案,通过读取输入文件并根据特定规则处理,输出True/False、Multiple Choice和Completion部分的答案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

闲来无趣,用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()


倒数第四行要根据自己需求修改~~~



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值