程序化Python程序自动评分

问题描述 投票:0回答:1

假设您想测试学生的基本编程技能。例如:

编写一个Python模块stduent_submission.py,1)将字符串分配给变量myString “$stackoverflow 很棒”,2) 删除 '$' 开头 3) 将其拆分为单词 4) 将单词“great”替换为 '惊人的'。假设每一步都是10分,并且没有偏项 信用。我想我们也需要模拟打印。

学生提交单个文件,我们应该测试stduent_submission.py吗?我们可以通过unittest或pytest来做到这一点吗?如果我们可以将学生成绩存储在字典中,比如 Student_dict = {'step1':0,'step2':10,'step3':10,'step4':0}

# stduent_submission.py
# Step 1: Assign a string to myString
myString = "$stackoverflow is great" 

# Step 2: Remove any non-alphanumeric character at the beginning
myString = myString.lstrip("$")

# Step 3: Split the string into words
words = myString.split()

# Step 4: Replace the word 'great' with 'awesome'
for i in range(len(words)):
    if words[i] == 'great':
        words[i] = 'awesome'

# Print the final result
final_string = ' '.join(words)
print(final_string)
python automated-tests procedural-programming
1个回答
0
投票

正如@Alexey 提到的

每一步之后我都会要求打印打印变量。如果比赛获得满分,否则为 0。可以使用如下简单代码来计算总分:

def compare_text(target, submitted):
target_lines = target.split('\n')
submitted_lines = submitted.split('\n')

total_points = 0

for i in range(min(len(target_lines), len(submitted_lines))):
    if target_lines[i] == submitted_lines[i]:
        total_points += 10

return total_points

# Example usage:
target_text = "Hello\nWorld\nPython"
submitted_text = "Hello\nWorld\nJava"

points = compare_text(target_text, submitted_text)
print("Total points:", points)
© www.soinside.com 2019 - 2024. All rights reserved.