Let’s assume you want to test basic programming skills of students. For example:
Write a python module, stduent_submission.py that 1) assigns to varaible myString the string
“$stackoverflow is great”, 2) remove ‘$’ at the
beginning 3) splits it into words 4) replace the word ‘great’ with
‘awesome’. assume each step is 10 points and there is no partial
credit.I assume we need to mock print as well.
Stduents submit a single file, should we go about testing stduent_submission.py? can we do this via unittest or pytest? It would be great if we could store student grade in a dictionary say 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)