Closed hugobowne closed 7 years ago
Hey Hugo, I'd use the following SCT:
test_import("pandas")
test_function("pandas.read_csv")
test_object("df")
test_object("col")
def test_for_iter():
test_expression_result()
def test_for_body():
def test_test():
test_function("langs_count.keys")
def test_body():
test_student_typed("\+=\s*1")
def test_orelse():
test_student_typed("=\s*1")
test_if_else(index = 1,
test = test_test,
body = test_body,
orelse = test_orelse)
test_for_loop(
index=1,
for_iter=test_for_iter,
body=test_for_body
)
test_object("langs_count")
test_function("print")
success_msg("Great work!")
Notice that:
test_if_else()
in there. I use test_function("langs_count.keys")
test_student_typed()
takes a regex by default, unless you set pattern = False
, than it takes the string literally.Some other notes:
test_object("df['lang']")
will not work; you can only specify actual names of objects inside test_object()
.Another option, that's possible better than the one above:
test_import("pandas")
test_function("pandas.read_csv")
test_object("df")
test_object("col")
def test_for_iter():
test_expression_result()
def test_for_body():
test_object_after_expression("langs_count",
extra_env = {'langs_count': {"en": 1}},
context_vals = ['et'])
test_object_after_expression("langs_count",
extra_env = {'langs_count': {"en": 1}},
context_vals = ['en'])
test_for_loop(
index=1,
for_iter=test_for_iter,
body=test_for_body
)
test_object("langs_count")
test_function("print")
success_msg("Great work!")
Here, I'm not using a test_if_else()
construct. Rather, I'm using test_object_after_expression
twice. Once for the case where the context val (entry
in this example) is et
and et
is not yet in a manually defined langs_count
list, and once where the entry
is en
and en
is already in the langs_count
list. This will indirectly check whether the student correctly updated the expression, you see?
I'd go with the second version. I had to do some tweaks to pythonwhat, so it's possible that this won't perfectly work before deployment on September 5th.
thanks, @filipsch , i'll check this out after deployment.
Hi! See this exercise: https://campus.datacamp.com/courses/1533/3850?ex=12
Code here: https://github.com/datacamp/HBA-python-problem-playground/blame/master/chapter1.md#L740
I am having a number of issues with this:
df['lang']
andtest_for_loop()
doesn't seem to work if i tryI have set
col=df['lang']
as a workaround but this isn't ideal at all: any ideas?However, when I submit
for entry in col1:
, it throws me a different error and doesn't tell me that i should usecol
instead ofcol1
. I have searched through documentation/wiki and can't find the solution. Any ideas?test_student_typed()
but this will have many problems as the students need to type two nearly identical things in different places!test_student_typed()
wasn't working as I expected: it did NOT accept the solution code UNTIL I usedpattern=False
. Can you explain why? I could not understand from documentation/wiki.thanks!
In the exercise that follows, I need to do this in a user-defined function also so fingers crossed!