Tests¶
Note
The examples are numbered and linkable, but numbers (and links) can change between builds of the documentation.
test_messaging.py¶
Example 1¶
No PEC
Solution code
round(1, 3)
No student code
No output
SCT
Ex().check_function("round").check_args(1).has_equal_value()
Result
Did you call <code>round()</code>?
No error
Example 2¶
No PEC
Solution code
round(1, 3)
Student code
round(1)
No output
SCT
Ex().check_function("round").check_args(1).has_equal_value()
Result
Check your call of <code>round()</code>. Did you specify the second argument?
No error
Example 3¶
No PEC
Solution code
round(1, 3)
Student code
round(1, a)
No output
SCT
Ex().check_function("round").check_args(1).has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the second argument? Running it generated an error: <code>name 'a' is not defined</code>.
Error
name 'a' is not defined
Example 4¶
No PEC
Solution code
round(1, 3)
Student code
round(1, 2)
No output
SCT
Ex().check_function("round").check_args(1).has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the second argument? Expected <code>3</code>, but got <code>2</code>.
No error
Example 5¶
No PEC
Solution code
round(1, 3)
Student code
round(1, ndigits = 2)
No output
SCT
Ex().check_function("round").check_args(1).has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the second argument? Expected <code>3</code>, but got <code>2</code>.
No error
Example 6¶
No PEC
Solution code
round(1, 3)
Student code
round(1)
No output
SCT
Ex().check_function("round").check_args("ndigits").has_equal_value()
Result
Check your call of <code>round()</code>. Did you specify the argument <code>ndigits</code>?
No error
Example 7¶
No PEC
Solution code
round(1, 3)
Student code
round(1, a)
No output
SCT
Ex().check_function("round").check_args("ndigits").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>ndigits</code>? Running it generated an error: <code>name 'a' is not defined</code>.
Error
name 'a' is not defined
Example 8¶
No PEC
Solution code
round(1, 3)
Student code
round(1, 2)
No output
SCT
Ex().check_function("round").check_args("ndigits").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>ndigits</code>? Expected <code>3</code>, but got <code>2</code>.
No error
Example 9¶
No PEC
Solution code
round(2)
Student code
round(3)
No output
SCT
Ex().check_function("round").check_args(0).has_equal_ast()
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2</code>, but got <code>3</code>.
No error
Example 10¶
No PEC
Solution code
round(2)
Student code
round(1 + 1)
No output
SCT
Ex().check_function("round").check_args(0).has_equal_ast()
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2</code>, but got <code>1 + 1</code>.
No error
Example 11¶
No PEC
Solution code
list("test")
Student code
list("wrong")
No output
SCT
Ex().check_function("list", signature = False).check_args(0).has_equal_ast()
Result
Check your call of <code>list()</code>. Did you correctly specify the first argument? Expected <code>"test"</code>, but got <code>"wrong"</code>.
No error
Example 12¶
No PEC
Solution code
list("test")
Student code
list("te" + "st")
No output
SCT
Ex().check_function("list", signature = False).check_args(0).has_equal_ast()
Result
Check your call of <code>list()</code>. Did you correctly specify the first argument? Expected <code>"test"</code>, but got <code>"te" + "st"</code>.
No error
Example 13¶
PEC
a = 3
b=3
Solution code
round(b)
Student code
round(a)
No output
SCT
Ex().check_function("round", signature = False).check_args(0).has_equal_ast()
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>b</code>, but got <code>a</code>.
No error
Example 14¶
PEC
a = 3
b=3
Solution code
round(b)
Student code
round(b + 1 - 1)
No output
SCT
Ex().check_function("round", signature = False).check_args(0).has_equal_ast()
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>b</code>, but got <code>b + 1 - 1</code>.
No error
Example 15¶
No PEC
Solution code
import pandas as pd; pd.DataFrame({'a': [1, 2, 3]})
Student code
import pandas as pd
No output
SCT
test_function_v2('pandas.DataFrame')
Result
Did you call <code>pd.DataFrame()</code>?
No error
Example 16¶
No PEC
Solution code
import pandas as pd; pd.DataFrame({'a': [1, 2, 3]})
Student code
import pandas as pad
No output
SCT
test_function_v2('pandas.DataFrame')
Result
Did you call <code>pad.DataFrame()</code>?
No error
Example 17¶
No PEC
Solution code
import numpy as np; x = np.random.rand(1)
Student code
import numpy as nump
No output
SCT
test_function_v2('numpy.random.rand')
Result
Did you call <code>nump.random.rand()</code>?
No error
Example 18¶
No PEC
Solution code
import numpy as np; x = np.random.rand(1)
Student code
from numpy.random import rand as r
No output
SCT
test_function_v2('numpy.random.rand')
Result
Did you call <code>r()</code>?
No error
Example 19¶
No PEC
Solution code
round(1)
round(2)
round(3)
No student code
No output
SCT
Ex().multi([ check_function("round", index=i).check_args(0).has_equal_value() for i in range(3) ])
Result
Did you call <code>round()</code>?
No error
Example 20¶
No PEC
Solution code
round(1)
round(2)
round(3)
Student code
round(1)
No output
SCT
Ex().multi([ check_function("round", index=i).check_args(0).has_equal_value() for i in range(3) ])
Result
Did you call <code>round()</code> twice?
No error
Example 21¶
No PEC
Solution code
round(1)
round(2)
round(3)
Student code
round(1)
round(5)
No output
SCT
Ex().multi([ check_function("round", index=i).check_args(0).has_equal_value() for i in range(3) ])
Result
Check your second call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2</code>, but got <code>5</code>.
No error
Example 22¶
No PEC
Solution code
round(1)
round(2)
round(3)
Student code
round(1)
round(2)
No output
SCT
Ex().multi([ check_function("round", index=i).check_args(0).has_equal_value() for i in range(3) ])
Result
Did you call <code>round()</code> three times?
No error
Example 23¶
No PEC
Solution code
round(1)
round(2)
round(3)
Student code
round(1)
round(2)
round(5)
No output
SCT
Ex().multi([ check_function("round", index=i).check_args(0).has_equal_value() for i in range(3) ])
Result
Check your third call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>3</code>, but got <code>5</code>.
No error
Example 24¶
PEC
import pandas as pd; df = pd.DataFrame({'a': [1, 2, 3], 'b': ['x', 'x', 'y']})
Solution code
df.groupby('b').a.value_counts(normalize = True)
Student code
df.groupby('a')
No output
SCT
from pythonwhat.signatures import sig_from_obj
import pandas as pd
Ex().check_function('df.groupby').check_args(0).has_equal_ast()
Ex().check_function('df.groupby.a.value_counts', signature = sig_from_obj(pd.Series.value_counts)).check_args('normalize').has_equal_ast()
Result
Check your call of <code>df.groupby()</code>. Did you correctly specify the first argument? Expected <code>'b'</code>, but got <code>'a'</code>.
No error
Example 25¶
PEC
import pandas as pd; df = pd.DataFrame({'a': [1, 2, 3], 'b': ['x', 'x', 'y']})
Solution code
df.groupby('b').a.value_counts(normalize = True)
Student code
df.groupby('b').a.value_counts()
No output
SCT
from pythonwhat.signatures import sig_from_obj
import pandas as pd
Ex().check_function('df.groupby').check_args(0).has_equal_ast()
Ex().check_function('df.groupby.a.value_counts', signature = sig_from_obj(pd.Series.value_counts)).check_args('normalize').has_equal_ast()
Result
Check your call of <code>df.groupby.a.value_counts()</code>. Did you specify the argument <code>normalize</code>?
No error
Example 26¶
PEC
import pandas as pd; df = pd.DataFrame({'a': [1, 2, 3], 'b': ['x', 'x', 'y']})
Solution code
df.groupby('b').a.value_counts(normalize = True)
Student code
df[df.b == 'x'].groupby('b').a.value_counts()
No output
SCT
from pythonwhat.signatures import sig_from_obj
import pandas as pd
Ex().check_function('df.groupby').check_args(0).has_equal_ast()
Ex().check_function('df.groupby.a.value_counts', signature = sig_from_obj(pd.Series.value_counts)).check_args('normalize').has_equal_ast()
Result
Check your call of <code>df.groupby.a.value_counts()</code>. Did you specify the argument <code>normalize</code>?
No error
Example 27¶
No PEC
Solution code
x = 5
No student code
No output
SCT
Ex().check_object("x").has_equal_value()
Result
Did you define the variable <code>x</code> without errors?
No error
Example 28¶
No PEC
Solution code
x = 5
Student code
x = 2
No output
SCT
Ex().check_object("x").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>2</code>.
No error
Example 29¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = 3
No output
SCT
test_data_frame('df', columns=['a'])
Result
Did you correctly define the pandas DataFrame <code>df</code>? Is it a DataFrame?
No error
Example 30¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = 3
No output
SCT
import pandas as pd; Ex().check_object('df', typestr = 'pandas DataFrame').is_instance(pd.DataFrame).check_keys('a').has_equal_value()
Result
Did you correctly define the pandas DataFrame <code>df</code>? Is it a DataFrame?
No error
Example 31¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({"b": [1]})
No output
SCT
test_data_frame('df', columns=['a'])
Result
Did you correctly define the pandas DataFrame <code>df</code>? There is no column <code>'a'</code>.
No error
Example 32¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({"b": [1]})
No output
SCT
import pandas as pd; Ex().check_object('df', typestr = 'pandas DataFrame').is_instance(pd.DataFrame).check_keys('a').has_equal_value()
Result
Did you correctly define the pandas DataFrame <code>df</code>? There is no column <code>'a'</code>.
No error
Example 33¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({"a": [1]})
No output
SCT
test_data_frame('df', columns=['a'])
Result
Did you correctly define the pandas DataFrame <code>df</code>? Did you correctly set the column <code>'a'</code>? Expected something different.
No error
Example 34¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({"a": [1]})
No output
SCT
import pandas as pd; Ex().check_object('df', typestr = 'pandas DataFrame').is_instance(pd.DataFrame).check_keys('a').has_equal_value()
Result
Did you correctly define the pandas DataFrame <code>df</code>? Did you correctly set the column <code>'a'</code>? Expected something different.
No error
Example 35¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
y = 3; df = pd.DataFrame({"a": [1]})
No output
SCT
test_data_frame('df', columns=['a'])
Result
Did you correctly define the pandas DataFrame <code>df</code>? Did you correctly set the column <code>'a'</code>? Expected something different.
No error
Example 36¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
y = 3; df = pd.DataFrame({"a": [1]})
No output
SCT
import pandas as pd; Ex().check_object('df', typestr = 'pandas DataFrame').is_instance(pd.DataFrame).check_keys('a').has_equal_value()
Result
Did you correctly define the pandas DataFrame <code>df</code>? Did you correctly set the column <code>'a'</code>? Expected something different.
No error
Example 37¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? There is no key <code>'a'</code>.
No error
Example 38¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {"b": 3}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? There is no key <code>'a'</code>.
No error
Example 39¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {"a": 3}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Did you correctly set the key <code>'a'</code>? Expected <code>2</code>, but got <code>3</code>.
No error
Example 40¶
No PEC
Solution code
x = {"a": 2}
Student code
y = 3; x = {"a": 3}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Did you correctly set the key <code>'a'</code>? Expected <code>2</code>, but got <code>3</code>.
No error
Example 41¶
No PEC
Solution code
x = round(1.23)
Student code
round(2.34)
No output
SCT
Ex().check_function('round').check_args(0).has_equal_value(incorrect_msg = 'argrwong')
Ex().check_object('x', missing_msg='objectnotdefined').has_equal_value('objectincorrect')
Result
argrwong
No error
Example 42¶
No PEC
Solution code
x = round(1.23)
Student code
round(1.23)
No output
SCT
Ex().check_function('round').check_args(0).has_equal_value(incorrect_msg = 'argrwong')
Ex().check_object('x', missing_msg='objectnotdefined').has_equal_value('objectincorrect')
Result
objectnotdefined
No error
Example 43¶
No PEC
Solution code
x = round(1.23)
Student code
x = round(1.23) + 1
No output
SCT
Ex().check_function('round').check_args(0).has_equal_value(incorrect_msg = 'argrwong')
Ex().check_object('x', missing_msg='objectnotdefined').has_equal_value('objectincorrect')
Result
objectincorrect
No error
Example 44¶
No PEC
Solution code
def test(a = 1): return a
No student code
No output
SCT
Ex().check_function_def('test').check_args('a').has_equal_part('is_default', msg='not default').has_equal_value()
Result
The system wants to check the definition of <code>test()</code> but hasn't found it.
No error
Example 45¶
No PEC
Solution code
def test(a = 1): return a
Student code
def test(b): return b
No output
SCT
Ex().check_function_def('test').check_args('a').has_equal_part('is_default', msg='not default').has_equal_value()
Result
Check the definition of <code>test()</code>. Did you specify the argument <code>a</code>?
No error
Example 46¶
No PEC
Solution code
def test(a = 1): return a
Student code
def test(a): return a
No output
SCT
Ex().check_function_def('test').check_args('a').has_equal_part('is_default', msg='not default').has_equal_value()
Result
Check the definition of <code>test()</code>. Did you correctly specify the argument <code>a</code>? not default
No error
Example 47¶
No PEC
Solution code
def test(a = 1): return a
Student code
def test(a = 2): return a
No output
SCT
Ex().check_function_def('test').check_args('a').has_equal_part('is_default', msg='not default').has_equal_value()
Result
Check the definition of <code>test()</code>. Did you correctly specify the argument <code>a</code>? Expected <code>1</code>, but got <code>2</code>.
No error
Example 48¶
No PEC
Solution code
def test(a, b): print(a + b); return a + b
No student code
No output
SCT
Ex().check_function_def('test').multi(
check_call('f(1, 2)').has_equal_value(),
check_call('f(1, 2)').has_equal_output(),
check_call('f(3, 1)').has_equal_value(),
check_call('f(1, "2")').has_equal_error()
)
Result
The system wants to check the definition of <code>test()</code> but hasn't found it.
No error
Example 49¶
No PEC
Solution code
def test(a, b): print(a + b); return a + b
Student code
def test(a, b): return 1
No output
SCT
Ex().check_function_def('test').multi(
check_call('f(1, 2)').has_equal_value(),
check_call('f(1, 2)').has_equal_output(),
check_call('f(3, 1)').has_equal_value(),
check_call('f(1, "2")').has_equal_error()
)
Result
Check the definition of <code>test()</code>. To verify it, we reran <code>test(1, 2)</code>. Expected <code>3</code>, but got <code>1</code>.
No error
Example 50¶
No PEC
Solution code
def test(a, b): print(a + b); return a + b
Student code
def test(a, b): return a + b
No output
SCT
Ex().check_function_def('test').multi(
check_call('f(1, 2)').has_equal_value(),
check_call('f(1, 2)').has_equal_output(),
check_call('f(3, 1)').has_equal_value(),
check_call('f(1, "2")').has_equal_error()
)
Result
Check the definition of <code>test()</code>. To verify it, we reran <code>test(1, 2)</code>. Expected the output <code>3</code>, but got <code>no printouts</code>.
No error
Example 51¶
No PEC
Solution code
def test(a, b): print(a + b); return a + b
Student code
def test(a, b):
if a == 3:
raise ValueError('wrong')
print(a + b)
return a + b
No output
SCT
Ex().check_function_def('test').multi(
check_call('f(1, 2)').has_equal_value(),
check_call('f(1, 2)').has_equal_output(),
check_call('f(3, 1)').has_equal_value(),
check_call('f(1, "2")').has_equal_error()
)
Result
Check the definition of <code>test()</code>. To verify it, we reran <code>test(3, 1)</code>. Running the higlighted expression generated an error: <code>wrong</code>.
No error
Example 52¶
No PEC
Solution code
def test(a, b): print(a + b); return a + b
Student code
def test(a, b): print(int(a) + int(b)); return int(a) + int(b)
No output
SCT
Ex().check_function_def('test').multi(
check_call('f(1, 2)').has_equal_value(),
check_call('f(1, 2)').has_equal_output(),
check_call('f(3, 1)').has_equal_value(),
check_call('f(1, "2")').has_equal_error()
)
Result
Check the definition of <code>test()</code>. To verify it, we reran <code>test(1, "2")</code>. Running the higlighted expression didn't generate an error, but it should!
No error
Example 53¶
No PEC
Solution code
echo_word = (lambda word1, echo: word1 * echo)
Student code
echo_word = (lambda word1, echo: word1 * echo * 2)
No output
SCT
Ex().check_lambda_function().check_call("f('test', 2)").has_equal_value()
Result
Check the first lambda function. To verify it, we reran it with the arguments <code>('test', 2)</code>. Expected <code>testtest</code>, but got <code>testtesttesttest</code>.
No error
Example 54¶
No PEC
Solution code
class A(str):
def __init__(self): pass
No student code
No output
SCT
Ex().check_class_def('A').multi( check_bases(0).has_equal_ast(), check_body().check_function_def('__init__').check_body().has_equal_ast() )
Result
The system wants to check the class definition of <code>A</code> but hasn't found it.
No error
Example 55¶
No PEC
Solution code
class A(str):
def __init__(self): pass
Student code
def A(x): pass
No output
SCT
Ex().check_class_def('A').multi( check_bases(0).has_equal_ast(), check_body().check_function_def('__init__').check_body().has_equal_ast() )
Result
The system wants to check the class definition of <code>A</code> but hasn't found it.
No error
Example 56¶
No PEC
Solution code
class A(str):
def __init__(self): pass
Student code
class A(): pass
No output
SCT
Ex().check_class_def('A').multi( check_bases(0).has_equal_ast(), check_body().check_function_def('__init__').check_body().has_equal_ast() )
Result
Check the class definition of <code>A</code>. Are you sure you defined the first base class?
No error
Example 57¶
No PEC
Solution code
class A(str):
def __init__(self): pass
Student code
class A(int): pass
No output
SCT
Ex().check_class_def('A').multi( check_bases(0).has_equal_ast(), check_body().check_function_def('__init__').check_body().has_equal_ast() )
Result
Check the class definition of <code>A</code>. Did you correctly specify the first base class? Expected <code>str</code>, but got <code>int</code>.
No error
Example 58¶
No PEC
Solution code
class A(str):
def __init__(self): pass
Student code
class A(str):
def __not_init__(self): pass
No output
SCT
Ex().check_class_def('A').multi( check_bases(0).has_equal_ast(), check_body().check_function_def('__init__').check_body().has_equal_ast() )
Result
Check the class definition of <code>A</code>. Did you correctly specify the body? The system wants to check the definition of <code>__init__()</code> but hasn't found it.
No error
Example 59¶
No PEC
Solution code
class A(str):
def __init__(self): pass
Student code
class A(str):
def __init__(self): print(1)
No output
SCT
Ex().check_class_def('A').multi( check_bases(0).has_equal_ast(), check_body().check_function_def('__init__').check_body().has_equal_ast() )
Result
Check the definition of <code>__init__()</code>. Did you correctly specify the body? Expected <code>pass</code>, but got <code>print(1)</code>.
No error
Example 60¶
No PEC
Solution code
import pandas as pd
No student code
No output
SCT
Ex().has_import('pandas', same_as=True)
Result
Did you import <code>pandas</code>?
No error
Example 61¶
No PEC
Solution code
import pandas as pd
Student code
import pandas
No output
SCT
Ex().has_import('pandas', same_as=True)
Result
Did you import <code>pandas</code> as <code>pd</code>?
No error
Example 62¶
No PEC
Solution code
import pandas as pd
Student code
import pandas as pan
No output
SCT
Ex().has_import('pandas', same_as=True)
Result
Did you import <code>pandas</code> as <code>pd</code>?
No error
Example 63¶
No PEC
Solution code
import pandas as pd
No student code
No output
SCT
Ex().has_import('pandas', same_as=True, not_imported_msg='wrong', incorrect_as_msg='wrongas')
Result
wrong
No error
Example 64¶
No PEC
Solution code
import pandas as pd
Student code
import pandas
No output
SCT
Ex().has_import('pandas', same_as=True, not_imported_msg='wrong', incorrect_as_msg='wrongas')
Result
wrongas
No error
Example 65¶
No PEC
Solution code
import pandas as pd
Student code
import pandas as pan
No output
SCT
Ex().has_import('pandas', same_as=True, not_imported_msg='wrong', incorrect_as_msg='wrongas')
Result
wrongas
No error
Example 66¶
No PEC
Solution code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items():
x = key + ' - ' + str(value)
print(x)
Student code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items(): x = key + ' -- ' + str(value)
No output
SCT
Ex().check_for_loop().check_body().set_context('a', 1).multi(has_equal_value(name = 'x'), has_equal_output())
Result
Check the first for loop. Did you correctly specify the body? Are you sure you assigned the correct value to <code>x</code>?
No error
Example 67¶
No PEC
Solution code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items():
x = key + ' - ' + str(value)
print(x)
Student code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items(): x = key + ' - ' + str(value)
No output
SCT
Ex().check_for_loop().check_body().set_context('a', 1).multi(has_equal_value(name = 'x'), has_equal_output())
Result
Check the first for loop. Did you correctly specify the body? Expected the output <code>a - 1</code>, but got <code>no printouts</code>.
No error
Example 68¶
No PEC
Solution code
result = (num for num in range(31))
Student code
result = (num for num in range(3))
No output
SCT
Ex().check_generator_exp().multi(check_iter().has_equal_value(), check_body().set_context(4).has_equal_value())
Result
Check the first generator expression. Did you correctly specify the iterable part? Expected <code>range(0, 31)</code>, but got <code>range(0, 3)</code>.
No error
Example 69¶
No PEC
Solution code
result = (num for num in range(31))
Student code
result = (num*2 for num in range(31))
No output
SCT
Ex().check_generator_exp().multi(check_iter().has_equal_value(), check_body().set_context(4).has_equal_value())
Result
Check the first generator expression. Did you correctly specify the body? Expected <code>4</code>, but got <code>8</code>.
No error
Example 70¶
No PEC
No solution code
Student code
c
No output
SCT
Ex().has_no_error()
Result
Have a look at the console: your code contains an error. Fix it and try again!
Error
name 'c' is not defined
Example 71¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
No student code
No output
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Did you define the variable <code>a</code> without errors?
No error
Example 72¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
a = 1
No output
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Did you define the variable <code>b</code> without errors?
No error
Example 73¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
a = 1; b = a + 1
No output
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Did you define the variable <code>c</code> without errors?
No error
Example 74¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
a = 1; b = a + 1; c = b + 1
No output
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Have you used <code>print(c)</code> to do the appropriate printouts?
No error
Example 75¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
print(4)
Student output
4
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Did you define the variable <code>a</code> without errors?
No error
Example 76¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
c = 3; print(c + 1)
Student output
4
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Have you used <code>print(c)</code> to do the appropriate printouts?
No error
Example 77¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
b = 3; c = b + 1; print(c)
Student output
4
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Did you define the variable <code>a</code> without errors?
No error
Example 78¶
No PEC
Solution code
a = 1; b = a + 1; c = b + 1; print(c)
Student code
a = 2; b = a + 1; c = b + 1
No output
SCT
Ex().test_correct(
has_printout(0),
F().test_correct(
check_object('c').has_equal_value(),
F().test_correct(
check_object('b').has_equal_value(),
check_object('a').has_equal_value()
)
)
)
Result
Did you correctly define the variable <code>a</code>? Expected <code>1</code>, but got <code>2</code>.
No error
Example 79¶
No PEC
Solution code
for i in range(2):
for j in range(2):
print(str(i) + "+" + str(j))
Student code
for i in range(2):
for j in range(2):
print(str(i) + "-" + str(j))
Student output
0-0
0-1
1-0
1-1
SCT
Ex().check_for_loop().check_body().check_for_loop().check_body().has_equal_output()
Result
Check the first for loop. Did you correctly specify the body? Expected the output <code>1+1</code>, but got <code>1-1</code>.
No error
Example 80¶
No PEC
Solution code
for i in range(2):
for j in range(2):
print(str(i) + "+" + str(j))
Student code
for i in range(2):
for j in range(2):
print(str(i) + "-" + str(j))
Student output
0-0
0-1
1-0
1-1
SCT
Ex().check_for_loop().check_body().check_for_loop().disable_highlighting().check_body().has_equal_output()
Result
Check the first for loop. Did you correctly specify the body? Check the first for loop. Did you correctly specify the body? Expected the output <code>1+1</code>, but got <code>1-1</code>.
No error
Example 81¶
No PEC
Solution code
x = [1]
Student code
x = [0]
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>[1]</code>, but got <code>[0]</code>.
No error
Example 82¶
No PEC
Solution code
x = [1]
Student code
x = [0]
No output
SCT
Ex().has_equal_value(name = 'x')
Result
Are you sure you assigned the correct value to <code>x</code>?
No error
Example 83¶
No PEC
Solution code
x = [1]
Student code
x = [0]
No output
SCT
Ex().has_equal_value(expr_code = 'x[0]')
Result
Running the expression <code>x[0]</code> didn't generate the expected result.
No error
Example 84¶
No PEC
Solution code
u = 'valid'
if u:
print('')
Student code
u = 'valid'
if u:
print('')
Student output
SCT
Ex().check_if_else().check_test().has_equal_value(expr_code = '__focus__ == \'valid\'')
Result
Great work!
No error
Example 85¶
No PEC
Solution code
u = 'valid'
if u:
print('')
Student code
u = 'wrong'
if u:
print('')
Student output
SCT
Ex().check_if_else().check_test().has_equal_value(expr_code = '__focus__ == \'valid\'')
Result
Check the first if statement. Did you correctly specify the condition? Running the expression <code>u == 'valid'</code> didn't generate the expected result.
No error
Example 86¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
No student code
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
The system wants to check the first if statement but hasn't found it.
No error
Example 87¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 10: x = 5
else: x = round(2.123)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 88¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 7
else: x = round(2.123)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 89¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = 8
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the else part? Did you call <code>round()</code>?
No error
Example 90¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.2121314)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2.123</code>, but got <code>2.2121314</code>.
No error
Example 91¶
No PEC
Solution code
x = 4
Student code
x = 3
No output
SCT
Ex().check_object('x').has_equal_value(incorrect_msg="__JINJA__:You did {{stu_eval}}, but should be {{sol_eval}}!")
Result
You did 3, but should be 4!
No error
Example 92¶
No PEC
Solution code
x = 4
Student code
x = 3
No output
SCT
Ex().check_object('x').has_equal_value(incorrect_msg="You did {{stu_eval}}, but should be {{sol_eval}}!")
Result
You did 3, but should be 4!
No error
test_check_logic.py¶
Example 1¶
No PEC
Solution code
a = 1
Student code
a = 1
No output
SCT
Ex().check_not(has_code('a'), msg = 'x')
Result
x
No error
Example 2¶
No PEC
Solution code
a = 1
Student code
a = 1
No output
SCT
Ex().check_not(has_code('a'), has_code('b'), msg = 'x')
Result
x
No error
Example 3¶
No PEC
Solution code
a = 1
Student code
a = 1
No output
SCT
Ex().check_not(has_code('b'), msg = 'x')
Result
Great work!
No error
Example 4¶
No PEC
Solution code
a = 1
Student code
a = 1
No output
SCT
Ex().check_not(has_code('b'), has_code('c'), msg = 'x')
Result
Great work!
No error
Example 5¶
No PEC
Solution code
a = 1
Student code
a = 1
No output
SCT
Ex().check_not(check_object('a').has_equal_value(override=1), msg = 'x')
Result
x
No error
Example 6¶
No PEC
Solution code
a = 1
Student code
a = 1
No output
SCT
Ex().check_not(check_object('a').has_equal_value(override=2), msg = 'x')
Result
Great work!
No error
Example 7¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_or(has_code('a'))
Result
Great work!
No error
Example 8¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_or(has_code('a'), has_code('b'))
Result
Great work!
No error
Example 9¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_or(has_code('b'))
Result
Could not find the correct pattern in your code.
No error
Example 10¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_or(has_code('b'), has_code('c'))
Result
Could not find the correct pattern in your code.
No error
Example 11¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(lambda: test_student_typed('a'))
Result
Great work!
No error
Example 12¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(test_student_typed('a'))
Result
Great work!
No error
Example 13¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(has_code('a'))
Result
Great work!
No error
Example 14¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(test_student_typed('a'))
Result
Great work!
No error
Example 15¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(lambda: test_student_typed('a'), lambda: test_student_typed('b'))
Result
Great work!
No error
Example 16¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(test_student_typed('a'), test_student_typed('b'))
Result
Great work!
No error
Example 17¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(has_code('a'), has_code('b'))
Result
Great work!
No error
Example 18¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(test_student_typed('a'), test_student_typed('b'))
Result
Great work!
No error
Example 19¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(lambda: test_student_typed('a'), lambda: test_student_typed('b'))
Result
Great work!
No error
Example 20¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(test_student_typed('a'), test_student_typed('b'))
Result
Great work!
No error
Example 21¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(has_code('a'), has_code('b'))
Result
Great work!
No error
Example 22¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(test_student_typed('a'), test_student_typed('b'))
Result
Great work!
No error
Example 23¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(lambda: test_student_typed('b'))
Result
Could not find the correct pattern in your code.
No error
Example 24¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(test_student_typed('b'))
Result
Could not find the correct pattern in your code.
No error
Example 25¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(has_code('b'))
Result
Could not find the correct pattern in your code.
No error
Example 26¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(test_student_typed('b'))
Result
Could not find the correct pattern in your code.
No error
Example 27¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(lambda: test_student_typed('b'), lambda: test_student_typed('c'))
Result
Could not find the correct pattern in your code.
No error
Example 28¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_or(test_student_typed('b'), test_student_typed('c'))
Result
Could not find the correct pattern in your code.
No error
Example 29¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(has_code('b'), has_code('c'))
Result
Could not find the correct pattern in your code.
No error
Example 30¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_or(test_student_typed('b'), test_student_typed('c'))
Result
Could not find the correct pattern in your code.
No error
Example 31¶
No PEC
No solution code
Student code
'def'
No output
SCT
Ex().check_or(has_code('a', not_typed_msg = 'a'), check_or(has_code('b'), has_code('c')))
Result
a
No error
Example 32¶
No PEC
No solution code
Student code
'def'
No output
SCT
Ex().test_or(has_code('a', not_typed_msg = 'a'), F().test_or(has_code('b'), has_code('c')))
Result
a
No error
Example 33¶
No PEC
No solution code
Student code
'def'
No output
SCT
test_or(test_student_typed('a', not_typed_msg = 'a'), test_or(test_student_typed('b'), test_student_typed('c')))
Result
a
No error
Example 34¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('a'), has_code('b'))
Result
Great work!
No error
Example 35¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('a'), has_code('c'))
Result
Great work!
No error
Example 36¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('b'), has_code('c', not_typed_msg='x'))
Result
x
No error
Example 37¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('b', not_typed_msg='x'), has_code('a'))
Result
x
No error
Example 38¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('a'), has_code('b'))
Result
Could not find the correct pattern in your code.
No error
Example 39¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('a'), has_code('c'))
Result
Could not find the correct pattern in your code.
No error
Example 40¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('b'), has_code('c', not_typed_msg='x'))
Result
x
No error
Example 41¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().check_correct(has_code('b', not_typed_msg='x'), has_code('a'))
Result
x
No error
Example 42¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(lambda: test_student_typed('a'), lambda: test_student_typed('b'))
Result
Great work!
No error
Example 43¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(test_student_typed('a'), test_student_typed('b'))
Result
Great work!
No error
Example 44¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(has_code('a'), has_code('b'))
Result
Great work!
No error
Example 45¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(test_student_typed('a'), test_student_typed('b'))
Result
Great work!
No error
Example 46¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(lambda: test_student_typed('a'), lambda: test_student_typed('c'))
Result
Great work!
No error
Example 47¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(test_student_typed('a'), test_student_typed('c'))
Result
Great work!
No error
Example 48¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(has_code('a'), has_code('c'))
Result
Great work!
No error
Example 49¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(test_student_typed('a'), test_student_typed('c'))
Result
Great work!
No error
Example 50¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(lambda: test_student_typed('b'), lambda: test_student_typed('c', not_typed_msg='x'))
Result
x
No error
Example 51¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(test_student_typed('b'), test_student_typed('c', not_typed_msg='x'))
Result
x
No error
Example 52¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(has_code('b'), has_code('c', not_typed_msg='x'))
Result
x
No error
Example 53¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(test_student_typed('b'), test_student_typed('c', not_typed_msg='x'))
Result
x
No error
Example 54¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(lambda: test_student_typed('b', not_typed_msg='x'), lambda: test_student_typed('a'))
Result
x
No error
Example 55¶
No PEC
No solution code
Student code
'a'
No output
SCT
test_correct(test_student_typed('b', not_typed_msg='x'), test_student_typed('a'))
Result
x
No error
Example 56¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(has_code('b', not_typed_msg='x'), has_code('a'))
Result
x
No error
Example 57¶
No PEC
No solution code
Student code
'a'
No output
SCT
Ex().test_correct(test_student_typed('b', not_typed_msg='x'), test_student_typed('a'))
Result
x
No error
Example 58¶
No PEC
No solution code
Student code
'def'
No output
SCT
Ex().check_correct(has_code('a'), check_correct(has_code('b'), has_code('c', not_typed_msg = 'c')))
Result
c
No error
Example 59¶
No PEC
No solution code
Student code
'def'
No output
SCT
Ex().test_correct(has_code('a'), F().test_correct(has_code('b'), has_code('c', not_typed_msg = 'c')))
Result
c
No error
Example 60¶
No PEC
No solution code
Student code
'def'
No output
SCT
test_correct(test_student_typed('a'), test_correct(test_student_typed('b'), test_student_typed('c', not_typed_msg = 'c')))
Result
c
No error
test_test_exercise.py¶
Example 1¶
PEC
#no pec
Solution code
x = 4
Student code
x = 4
No output
SCT
test_object("x")
success_msg("nice")
Result
nice
No error
Example 2¶
PEC
#no pec
Solution code
x = 6
Student code
x = 4
No output
SCT
test_object("x")
success_msg("nice")
Result
Did you correctly define the variable <code>x</code>? Expected <code>6</code>, but got <code>4</code>.
No error
Example 3¶
PEC
#no pec
Solution code
x = 6
Student code
x = y
No output
SCT
# no sct
Result
Your code generated an error. Fix it and try again!
Error
name 'y' is not defined
Example 4¶
PEC
# no pec
Solution code
x = 6
Student code
print "yolo"
No output
SCT
test_object("x")
Result
Your code can not be executed due to a syntax error:<br><code>Missing parentheses in call to 'print' (script.py, line 1).</code>
Error
Missing parentheses in call to 'print' (<string>, line 1)
Example 5¶
PEC
# no pec
Solution code
x = 6
Student code
print("yolo")
No output
SCT
test_object("x")
Result
Your code could not be parsed due to an error in the indentation:<br><code>unexpected indent (script.py, line 1).</code>
Error
unexpected indent (<string>, line 1)
Example 6¶
PEC
# no pec
Solution code
x = 6
No student code
No output
SCT
test_object("x")
Result
Did you define the variable <code>x</code> without errors?
No error
test_check_object.py¶
Example 1¶
No PEC
Solution code
x = 100
No student code
No output
SCT
test_object('x', undefined_msg='udm', incorrect_msg='icm')
Result
udm
No error
Example 2¶
No PEC
Solution code
x = 100
No student code
No output
SCT
Ex().check_object('x', missing_msg='udm').has_equal_value(incorrect_msg='icm')
Result
udm
No error
Example 3¶
No PEC
Solution code
x = 100
Student code
x = 1
No output
SCT
test_object('x', undefined_msg='udm', incorrect_msg='icm')
Result
icm
No error
Example 4¶
No PEC
Solution code
x = 100
Student code
x = 1
No output
SCT
Ex().check_object('x', missing_msg='udm').has_equal_value(incorrect_msg='icm')
Result
icm
No error
Example 5¶
No PEC
Solution code
x = 100
Student code
x = 100
No output
SCT
test_object('x', undefined_msg='udm', incorrect_msg='icm')
Result
Great work!
No error
Example 6¶
No PEC
Solution code
x = 100
Student code
x = 100
No output
SCT
Ex().check_object('x', missing_msg='udm').has_equal_value(incorrect_msg='icm')
Result
Great work!
No error
Example 7¶
No PEC
Solution code
x = filter(lambda x: x > 0, [1, 1])
Student code
x = filter(lambda x: x > 0, [0, 1])
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code><filter object at 0x7f792c4b5198></code>, but got <code><filter object at 0x7f792c4b5b00></code>.
No error
Example 8¶
No PEC
Solution code
x = filter(lambda x: x > 0, [1, 1])
Student code
x = filter(lambda x: x > 0, [1, 1])
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Great work!
No error
Example 9¶
PEC
import numpy as np
Solution code
x = (np.array([1, 2]), np.array([3, 4]))
Student code
x = (np.array([1, 2]), np.array([1, 2]))
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>(array([1, 2]), array([3, 4]))</code>, but got <code>(array([1, 2]), array([1, 2]))</code>.
No error
Example 10¶
PEC
import numpy as np
Solution code
x = (np.array([1, 2]), np.array([3, 4]))
Student code
x = (np.array([1, 2]), np.array([3, 4]))
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Great work!
No error
Example 11¶
No PEC
Solution code
x = [4, 5, 6]
Student code
x = [1, 2, 3]
No output
SCT
Ex().check_object("x").has_equal_value(func = lambda x,y: len(x) == len(y))
Result
Great work!
No error
Example 12¶
No PEC
Solution code
x = [4, 5, 6]
Student code
x = [1, 2, 3, 4]
No output
SCT
Ex().check_object("x").has_equal_value(func = lambda x,y: len(x) == len(y))
Result
Did you correctly define the variable <code>x</code>? Expected <code>[4, 5, 6]</code>, but got <code>[1, 2, 3, 4]</code>.
No error
Example 13¶
PEC
import numpy as np
Solution code
arr = np.array([1, 2, 3, 4])
Student code
arr = 4
No output
SCT
import numpy; Ex().check_object('arr').is_instance(numpy.ndarray)
Result
Did you correctly define the variable <code>arr</code>? Is it a ndarray?
No error
Example 14¶
PEC
import numpy as np
Solution code
arr = np.array([1, 2, 3, 4])
Student code
arr = np.array([1])
No output
SCT
import numpy; Ex().check_object('arr').is_instance(numpy.ndarray)
Result
Great work!
No error
Example 15¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
No student code
No output
SCT
test_data_frame('df', columns=['a'], undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
udm
No error
Example 16¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
No student code
No output
SCT
test_data_frame('df', columns=None, undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
udm
No error
Example 17¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
No student code
No output
SCT
import pandas as pd
Ex().check_object('df', missing_msg='udm', expand_msg=''). is_instance(pd.DataFrame, not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
udm
No error
Example 18¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
No student code
No output
SCT
import pandas as pd
Ex().check_df('df', missing_msg='udm', expand_msg='', not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
udm
No error
Example 19¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = 3
No output
SCT
test_data_frame('df', columns=['a'], undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
ndfm
No error
Example 20¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = 3
No output
SCT
test_data_frame('df', columns=None, undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
ndfm
No error
Example 21¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = 3
No output
SCT
import pandas as pd
Ex().check_object('df', missing_msg='udm', expand_msg=''). is_instance(pd.DataFrame, not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
ndfm
No error
Example 22¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = 3
No output
SCT
import pandas as pd
Ex().check_df('df', missing_msg='udm', expand_msg='', not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
ndfm
No error
Example 23¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "b": [1]})
No output
SCT
test_data_frame('df', columns=['a'], undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
ucm
No error
Example 24¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "b": [1]})
No output
SCT
test_data_frame('df', columns=None, undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
ucm
No error
Example 25¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "b": [1]})
No output
SCT
import pandas as pd
Ex().check_object('df', missing_msg='udm', expand_msg=''). is_instance(pd.DataFrame, not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
ucm
No error
Example 26¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "b": [1]})
No output
SCT
import pandas as pd
Ex().check_df('df', missing_msg='udm', expand_msg='', not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
ucm
No error
Example 27¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1]})
No output
SCT
test_data_frame('df', columns=['a'], undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
icm
No error
Example 28¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1]})
No output
SCT
test_data_frame('df', columns=None, undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
icm
No error
Example 29¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1]})
No output
SCT
import pandas as pd
Ex().check_object('df', missing_msg='udm', expand_msg=''). is_instance(pd.DataFrame, not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
icm
No error
Example 30¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1]})
No output
SCT
import pandas as pd
Ex().check_df('df', missing_msg='udm', expand_msg='', not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
icm
No error
Example 31¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3] })
No output
SCT
test_data_frame('df', columns=['a'], undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
Great work!
No error
Example 32¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3] })
No output
SCT
test_data_frame('df', columns=None, undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
Great work!
No error
Example 33¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3] })
No output
SCT
import pandas as pd
Ex().check_object('df', missing_msg='udm', expand_msg=''). is_instance(pd.DataFrame, not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
Great work!
No error
Example 34¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3] })
No output
SCT
import pandas as pd
Ex().check_df('df', missing_msg='udm', expand_msg='', not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
Great work!
No error
Example 35¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3], "b": [3, 4, 5] })
No output
SCT
test_data_frame('df', columns=['a'], undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
Great work!
No error
Example 36¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3], "b": [3, 4, 5] })
No output
SCT
test_data_frame('df', columns=None, undefined_msg='udm', not_data_frame_msg='ndfm', undefined_cols_msg='ucm', incorrect_msg='icm')
Result
Great work!
No error
Example 37¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3], "b": [3, 4, 5] })
No output
SCT
import pandas as pd
Ex().check_object('df', missing_msg='udm', expand_msg=''). is_instance(pd.DataFrame, not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
Great work!
No error
Example 38¶
PEC
import pandas as pd
Solution code
df = pd.DataFrame({"a": [1, 2, 3]})
Student code
df = pd.DataFrame({ "a": [1, 2, 3], "b": [3, 4, 5] })
No output
SCT
import pandas as pd
Ex().check_df('df', missing_msg='udm', expand_msg='', not_instance_msg='ndfm'). check_keys('a', missing_msg='ucm').has_equal_value(incorrect_msg='icm')
Result
Great work!
No error
Example 39¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? There is no key <code>'a'</code>.
No error
Example 40¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {"b": 3}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? There is no key <code>'a'</code>.
No error
Example 41¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {"a": 3}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Did you correctly set the key <code>'a'</code>? Expected <code>2</code>, but got <code>3</code>.
No error
Example 42¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {"a": 2}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Great work!
No error
Example 43¶
No PEC
Solution code
x = {"a": 2}
Student code
x = {"a": 2, "b": 3}
No output
SCT
Ex().check_object("x").check_keys("a").has_equal_value()
Result
Great work!
No error
Example 44¶
PEC
import pandas as pd
users = pd.read_csv('https://s3.amazonaws.com/assets.datacamp.com/production/course_1650/datasets/users.csv')
Solution code
pivot = users.pivot(index='weekday', columns='city')
Student code
pivot = users.pivot(index='weekday', columns='city')
No output
SCT
Ex().test_data_frame('pivot')
Result
Great work!
No error
Example 45¶
PEC
import pandas as pd
users = pd.read_csv('https://s3.amazonaws.com/assets.datacamp.com/production/course_1650/datasets/users.csv')
Solution code
pivot = users.pivot(index='weekday', columns='city')
Student code
pivot = users.pivot(index='weekday', columns='city')
No output
SCT
Ex().check_df('pivot').check_keys(('visitors', 'Austin')).has_equal_value()
Result
Great work!
No error
Example 46¶
PEC
import scipy.io; from urllib.request import urlretrieve; urlretrieve('https://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/ja_data2.mat', 'albeck_gene_expression.mat')
Solution code
mat = scipy.io.loadmat('albeck_gene_expression.mat')
Student code
mat = scipy.io.loadmat('albeck_gene_expression.mat')
No output
SCT
Ex().check_object('mat').has_equal_value()
Result
Great work!
No error
Example 47¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("a").has_equal_value()
Result
Did you correctly define the variable <code>a</code>? Expected <code>10</code>, but got <code>1</code>.
No error
Example 48¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("c").has_equal_value()
Result
Did you correctly define the variable <code>c</code>? Expected <code>30</code>, but got <code>3</code>.
No error
Example 49¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("d").has_equal_value()
Result
Did you correctly define the variable <code>d</code>? Expected <code>40</code>, but got <code>4</code>.
No error
Example 50¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("e").has_equal_value()
Result
Did you correctly define the variable <code>e</code>? Expected <code>50</code>, but got <code>5</code>.
No error
Example 51¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("f").has_equal_value()
Result
Did you correctly define the variable <code>f</code>? Expected <code>60</code>, but got <code>6</code>.
No error
Example 52¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("g").has_equal_value()
Result
Did you correctly define the variable <code>g</code>? Expected <code>70</code>, but got <code>7</code>.
No error
Example 53¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("h").has_equal_value()
Result
Did you correctly define the variable <code>h</code>? Expected <code>80</code>, but got <code>8</code>.
No error
Example 54¶
No PEC
Solution code
if True:
a = 10
if False:
b = 20
else:
c = 30
for i in range(2):
d = 40
x = 2
while x > 0:
e = 50
x -= 1
try:
f = 60
except:
pass
try:
g = 70
except:
pass
finally:
h = 80
# 2 assignments
i = 90
if True:
i = 90
Student code
if True:
a = 1
if False:
b = 2
else:
c = 3
for i in range(2):
d = 4
x = 2
while x > 0:
e = 5
x -= 1
try:
f = 6
except:
pass
try:
g = 7
except:
pass
finally:
h = 8
# 2 assignments
i = 9
if True:
i = 9
No output
SCT
Ex().check_object("i").has_equal_value()
Result
Did you correctly define the variable <code>i</code>? Expected <code>90</code>, but got <code>9</code>.
No error
Example 55¶
No PEC
Solution code
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df.columns = ["c", "d"]
df2 = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df2.columns = ["c", "d"]
Student code
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df.columns = ["c", "d"]
df2 = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df2.columns = ["e", "f"]
No output
SCT
Ex().check_object('df').has_equal_value()
Result
Great work!
No error
Example 56¶
No PEC
Solution code
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df.columns = ["c", "d"]
df2 = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df2.columns = ["c", "d"]
Student code
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df.columns = ["c", "d"]
df2 = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df2.columns = ["e", "f"]
No output
SCT
Ex().check_object('df2').has_equal_value()
Result
Did you correctly define the variable <code>df2</code>? Expected something different.
No error
test_check_function_def.py¶
Example 1¶
No PEC
Solution code
def shout(word): print(word + '!!')
Student code
def shout(word): print(word + '!!')
No output
SCT
Ex().check_function_def('shout').check_body().set_context('test').has_equal_output()
Result
Great work!
No error
Example 2¶
No PEC
Solution code
def shout(word): print(word + '!!')
Student code
def shout(word): print(word + '!!')
No output
SCT
test_function_definition('shout', body = lambda: test_expression_output(context_vals = ['help']))
Result
Great work!
No error
Example 3¶
No PEC
Solution code
def shout(word): print(word + '!!')
Student code
def shout(word): print(word + '!!')
No output
SCT
test_function_definition('shout', body = test_expression_output(context_vals = ['help']))
Result
Great work!
No error
Example 4¶
No PEC
Solution code
def my_fun(*x, **y): pass
Student code
def my_fun(*x, **y): pass
No output
SCT
Ex().check_function_def('my_fun').multi(
check_args('*args').has_equal_part('name', msg='x'),
check_args('**kwargs').has_equal_part('name', msg='x')
)
Result
Great work!
No error
Example 5¶
No PEC
Solution code
def my_fun(*x, **y): pass
Student code
def my_fun(*x, **y): pass
No output
SCT
Ex().test_function_definition('my_fun')
Result
Great work!
No error
Example 6¶
No PEC
Solution code
def f(a, b): pass
Student code
def f(): pass
No output
SCT
Ex().check_function_def('f').has_equal_part_len('args', unequal_msg='wrong')
Result
Check the definition of <code>f()</code>. wrong
No error
Example 7¶
No PEC
Solution code
def f(a, b): pass
Student code
def f(): pass
No output
SCT
Ex().test_function_definition('f')
Result
Check the definition of <code>f()</code>. You should define with 2 arguments, instead got 0.
No error
Example 8¶
No PEC
Solution code
def f(a, b): pass
Student code
def f(a): pass
No output
SCT
Ex().check_function_def('f').has_equal_part_len('args', unequal_msg='wrong')
Result
Check the definition of <code>f()</code>. wrong
No error
Example 9¶
No PEC
Solution code
def f(a, b): pass
Student code
def f(a): pass
No output
SCT
Ex().test_function_definition('f')
Result
Check the definition of <code>f()</code>. You should define with 2 arguments, instead got 1.
No error
Example 10¶
No PEC
Solution code
def f(a, b): pass
Student code
def f(a, b): pass
No output
SCT
Ex().check_function_def('f').has_equal_part_len('args', unequal_msg='wrong')
Result
Great work!
No error
Example 11¶
No PEC
Solution code
def f(a, b): pass
Student code
def f(a, b): pass
No output
SCT
Ex().test_function_definition('f')
Result
Great work!
No error
Example 12¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', results=[[1]])
Result
Great work!
No error
Example 13¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', results=[(1,)])
Result
Great work!
No error
Example 14¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', outputs=[[1]])
Result
Great work!
No error
Example 15¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', outputs=[(1,)])
Result
Great work!
No error
Example 16¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', errors=[['1']])
Result
Great work!
No error
Example 17¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', errors=[('1',)])
Result
Great work!
No error
Example 18¶
No PEC
Solution code
def my_fun(a):
print(a + 2)
return a + 2
Student code
def my_fun(a):
print(a + 2)
return a + 2
No output
SCT
Ex().test_function_definition('my_fun', errors=['1'])
Result
Great work!
No error
test_check_list_comp.py¶
Example 1¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
No student code
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
The system wants to check the first list comprehension but hasn't found it.
No error
Example 2¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key for key in x.keys()]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check the first list comprehension. Did you correctly specify the iterable part? Expected <code>[('a', 2), ('b', 3), ('c', 4), ('d', 'test')]</code>, but got <code>['a', 'b', 'c', 'd']</code>.
No error
Example 3¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[a + str(b) for a,b in x.items()]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check the first list comprehension. Have you used the correct iterator variables?
No error
Example 4¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + '_' + str(val) for key,val in x.items()]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check the first list comprehension. Did you correctly specify the body? Expected <code>a2</code>, but got <code>a_2</code>.
No error
Example 5¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items()]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check the first list comprehension. Have you used 2 ifs?
No error
Example 6¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if hasattr(key, 'test') if hasattr(key, 'test')]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check the first list comprehension. Did you correctly specify the first if? Did you call <code>isinstance()</code>?
No error
Example 7¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if isinstance(key, str) if hasattr(key, 'test')]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check the first list comprehension. Did you correctly specify the second if? Did you call <code>isinstance()</code>?
No error
Example 8¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(key, str)]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Check your call of <code>isinstance()</code>. Did you correctly specify the argument <code>obj</code>? Expected <code>val</code>, but got <code>key</code>.
No error
Example 9¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, str)]
No output
SCT
test_list_comp(index=1,
not_called_msg=None,
comp_iter=lambda: test_expression_result(),
iter_vars_names=True,
incorrect_iter_vars_msg=None,
body=lambda: test_expression_result(context_vals = ['a', 2]),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False]),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False])],
insufficient_ifs_msg=None)
Result
Great work!
No error
Example 10¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
No student code
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
notcalled
No error
Example 11¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key for key in x.keys()]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
iterincorrect
No error
Example 12¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[a + str(b) for a,b in x.items()]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
Check the first list comprehension. incorrectitervars
No error
Example 13¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + '_' + str(val) for key,val in x.items()]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
bodyincorrect
No error
Example 14¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items()]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
Check the first list comprehension. insufficientifs
No error
Example 15¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if hasattr(key, 'test') if hasattr(key, 'test')]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
notcalled1
No error
Example 16¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if isinstance(key, str) if hasattr(key, 'test')]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
notcalled2
No error
Example 17¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(key, str)]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
incorrect2
No error
Example 18¶
PEC
x = {'a': 2, 'b':3, 'c':4, 'd':'test'}
Solution code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, int)]
Student code
[key + str(val) for key,val in x.items() if isinstance(key, str) if isinstance(val, str)]
No output
SCT
test_list_comp(index=1,
not_called_msg='notcalled',
comp_iter=lambda: test_expression_result(incorrect_msg = 'iterincorrect'),
iter_vars_names=True,
incorrect_iter_vars_msg='incorrectitervars',
body=lambda: test_expression_result(context_vals = ['a', 2], incorrect_msg = 'bodyincorrect'),
ifs=[lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled1', incorrect_msg = 'incorrect2'),
lambda: test_function_v2('isinstance', params = ['obj'], do_eval = [False], not_called_msg = 'notcalled2', incorrect_msg = 'incorrect2')],
insufficient_ifs_msg='insufficientifs')
Result
Great work!
No error
Example 19¶
No PEC
Solution code
[[col for col in range(5)] for row in range(5)]
Student code
[[col + 1 for col in range(5)] for row in range(5)]
No output
SCT
test_list_comp(1, body = lambda: test_list_comp(1, body = lambda: test_expression_result(context_vals = [4])))
Result
Check the first list comprehension. Did you correctly specify the body? Expected <code>4</code>, but got <code>5</code>.
No error
Example 20¶
No PEC
Solution code
[[col for col in range(5)] for row in range(5)]
Student code
[[col for col in range(5)] for row in range(5)]
No output
SCT
test_list_comp(1, body = lambda: test_list_comp(1, body = lambda: test_expression_result(context_vals = [4])))
Result
Great work!
No error
Example 21¶
PEC
x = {'a':1, 'b':2}
Solution code
[key for key, value in x.items()]
Student code
[a for a in x.items()]
No output
SCT
test_list_comp(1, iter_vars_names=False)
Result
Check the first list comprehension. Have you used 2 iterator variables?
No error
Example 22¶
PEC
x = {'a':1, 'b':2}
Solution code
[key for key, value in x.items()]
Student code
[a for a in x.items()]
No output
SCT
Ex().check_list_comp(0).has_context()
Result
Check the first list comprehension. Have you used the correct iterator variable names? Was expecting <code>(key, value)</code> but got <code>a</code>.
No error
Example 23¶
PEC
x = {'a':1, 'b':2}
Solution code
[key for key, value in x.items()]
Student code
[a for a,b in x.items()]
No output
SCT
test_list_comp(1, iter_vars_names=False)
Result
Great work!
No error
Example 24¶
PEC
x = {'a':1, 'b':2}
Solution code
[key for key, value in x.items()]
Student code
[a for a,b in x.items()]
No output
SCT
Ex().check_list_comp(0).has_context()
Result
Great work!
No error
test_converters.py¶
Example 1¶
No PEC
Solution code
x = {'a': 1, 'b': 2}; print(x.keys())
Student code
x = {'b':2, 'a': 1}; print(x.keys())
Student output
dict_keys(['b', 'a'])
SCT
Ex().check_function('print').check_args('value').has_equal_value()
Result
Great work!
No error
Example 2¶
No PEC
Solution code
x = {'france':'paris', 'spain':'madrid'}.items()
Student code
x = {'spain':'madrid', 'france':'paris'}.items()
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Great work!
No error
Example 3¶
PEC
import requests; from bs4 import BeautifulSoup
Solution code
soup = BeautifulSoup(requests.get('https://www.python.org/~guido/').text, 'html5lib'); print(soup.title); a_tags = soup.find_all('a')
Student code
soup = BeautifulSoup(requests.get('https://www.python.org/~guido/').text, 'html5lib'); print(soup.title); a_tags = soup.find_all('a')
Student output
<title>Guido's Personal Home Page</title>
SCT
Ex().check_object('soup').has_equal_value(); Ex().check_function('print').check_args('value').has_equal_value(); Ex().check_object('a_tags').has_equal_value()
Result
Great work!
No error
Example 4¶
PEC
import numpy as np; import h5py; file = 'LIGO_data.hdf5'; from urllib.request import urlretrieve; urlretrieve('https://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/L-L1_LOSC_4_V1-1126259446-32.hdf5', 'LIGO_data.hdf5')
Solution code
data = h5py.File(file, 'r'); group = data['strain']
Student code
data = h5py.File(file, 'r'); group = data['strain']
No output
SCT
Ex().check_object('file').has_equal_value(); Ex().check_object('data').has_equal_value(); Ex().check_object('group').has_equal_value()
Result
Great work!
No error
test_check_if_else.py¶
Example 1¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
No student code
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
The system wants to check the first if expression but hasn't found it.
No error
Example 2¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
No student code
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
The system wants to check the first if expression but hasn't found it.
No error
Example 3¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
No student code
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
The system wants to check the first if statement but hasn't found it.
No error
Example 4¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 10: x = 5
else: x = round(2.123)
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 5¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 10: x = 5
else: x = round(2.123)
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 6¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 10: x = 5
else: x = round(2.123)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 7¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 7
else: x = round(2.123)
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 8¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 7
else: x = round(2.123)
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 9¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 7
else: x = round(2.123)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 10¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x,y = 7,12
else: x = round(2.123)
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 11¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x,y = 7,12
else: x = round(2.123)
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 12¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x,y = 7,12
else: x = round(2.123)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 13¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = 8
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
Check the first if expression. Did you correctly specify the else part? Did you call <code>round()</code>?
No error
Example 14¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = 8
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
Check the first if expression. Did you correctly specify the else part? Did you call <code>round()</code>?
No error
Example 15¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = 8
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check the first if statement. Did you correctly specify the else part? Did you call <code>round()</code>?
No error
Example 16¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.2121314)
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2.123</code>, but got <code>2.2121314</code>.
No error
Example 17¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.2121314)
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2.123</code>, but got <code>2.2121314</code>.
No error
Example 18¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.2121314)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>2.123</code>, but got <code>2.2121314</code>.
No error
Example 19¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.123)
No output
SCT
def condition_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
test_if_else(index=1,
test = condition_test,
body = lambda: test_student_typed(r'x\s*=\s*5'),
orelse = lambda: test_function('round'))
Result
Great work!
No error
Example 20¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.123)
No output
SCT
condition_test = [
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
]
test_if_else(index=1,
test = condition_test,
body = test_student_typed(r'x\s*=\s*5'),
orelse = test_function('round'))
Result
Great work!
No error
Example 21¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
else: x = round(2.123)
Student code
if offset > 8: x = 5
else: x = round(2.123)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7,10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
Result
Great work!
No error
Example 22¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
No student code
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
The system wants to check the first if expression but hasn't found it.
No error
Example 23¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
No student code
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
The system wants to check the first if expression but hasn't found it.
No error
Example 24¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
No student code
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
The system wants to check the first if statement but hasn't found it.
No error
Example 25¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 9: x = 5
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 26¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 9: x = 5
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 27¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 9: x = 5
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if statement. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 28¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 6
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 29¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 6
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 30¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 6
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if statement. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 31¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 6: x = 7
else: x = round(9)
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 32¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 6: x = 7
else: x = round(9)
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 33¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 6: x = 7
else: x = round(9)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if statement. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 34¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 8
else: x = round(9)
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 35¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 8
else: x = round(9)
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 36¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 8
else: x = round(9)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if statement. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 37¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(10)
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>9</code>, but got <code>10</code>.
No error
Example 38¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(10)
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>9</code>, but got <code>10</code>.
No error
Example 39¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(10)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>9</code>, but got <code>10</code>.
No error
Example 40¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
def test_test():
test_expression_result({"offset": 7})
test_expression_result({"offset": 8})
test_expression_result({"offset": 9})
def body_test():
test_student_typed('5')
def orelse_test():
def test_test2():
test_expression_result({"offset": 4})
test_expression_result({"offset": 5})
test_expression_result({"offset": 6})
def body_test2():
test_student_typed('7')
def orelse_test2():
test_function('round')
test_if_else(index = 1,
test = test_test2,
body = body_test2,
orelse = orelse_test2)
test_if_else(index=1,
test=test_test,
body=body_test,
orelse=orelse_test)
Result
Great work!
No error
Example 41¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
test_if_else(index=1,
test=[
test_expression_result({"offset": 7}),
test_expression_result({"offset": 8}),
test_expression_result({"offset": 9})
],
body=test_student_typed('5'),
orelse=test_if_else(index = 1,
test=[
test_expression_result({"offset": 4}),
test_expression_result({"offset": 5}),
test_expression_result({"offset": 6})
],
body = test_student_typed('7'),
orelse = test_function('round')
)
)
Result
Great work!
No error
Example 42¶
PEC
offset = 8
Solution code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
Student code
if offset > 8: x = 5
elif offset > 5: x = 7
else: x = round(9)
No output
SCT
Ex().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code(r'x\s*=\s*5'),
check_orelse().check_if_else().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Great work!
No error
Example 43¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
No student code
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
The system wants to check the first if expression but hasn't found it.
No error
Example 44¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
Student code
x = 5 if offset > 9 else 7 if offset > 5 else round(9)
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 45¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
Student code
x = 6 if offset > 8 else 7 if offset > 5 else round(9)
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 46¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
Student code
x = 5 if offset > 8 else 7 if offset > 6 else round(9)
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if expression. Did you correctly specify the condition? Expected <code>True</code>, but got <code>False</code>.
No error
Example 47¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
Student code
x = 5 if offset > 8 else 8 if offset > 5 else round(9)
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check the first if expression. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 48¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
Student code
x = 5 if offset > 8 else 7 if offset > 5 else round(10)
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>9</code>, but got <code>10</code>.
No error
Example 49¶
PEC
offset = 8
Solution code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
Student code
x = 5 if offset > 8 else 7 if offset > 5 else round(9)
No output
SCT
Ex().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(7, 10) ]),
check_body().has_code('5'),
check_orelse().check_if_exp().multi(
check_test().multi([ set_env(offset = i).has_equal_value() for i in range(4, 7) ]),
check_body().has_code('7'),
check_orelse().check_function('round').check_args(0).has_equal_value()
)
)
Result
Great work!
No error
test_docs.py¶
Example 1¶
No PEC
Solution code
x = 4
if x > 0:
print("x is strictly positive")
Student code
x = 4
if x > 0:
print("x is strictly positive")
Student output
x is strictly positive
SCT
Ex().check_if_else().multi(
check_test().multi(
set_env(x = -1).has_equal_value(), # chain A1
set_env(x = 1).has_equal_value(), # chain A2
set_env(x = 0).has_equal_value() # chain A3
),
check_body().check_function('print', 0).check_args('value').has_equal_value() # chain B
)
Result
Great work!
No error
Example 2¶
No PEC
Solution code
x = 4
if x > 0:
print("x is strictly positive")
Student code
x = 4
if 0 < x:
print("x is strictly positive")
Student output
x is strictly positive
SCT
Ex().check_if_else().multi(
check_test().multi(
set_env(x = -1).has_equal_value(), # chain A1
set_env(x = 1).has_equal_value(), # chain A2
set_env(x = 0).has_equal_value() # chain A3
),
check_body().check_function('print', 0).check_args('value').has_equal_value() # chain B
)
Result
Great work!
No error
Example 3¶
No PEC
Solution code
x = 4
if x > 0:
print("x is strictly positive")
Student code
x = 4
if x >= 0:
print("x is strictly positive")
Student output
x is strictly positive
SCT
Ex().check_if_else().multi(
check_test().multi(
set_env(x = -1).has_equal_value(), # chain A1
set_env(x = 1).has_equal_value(), # chain A2
set_env(x = 0).has_equal_value() # chain A3
),
check_body().check_function('print', 0).check_args('value').has_equal_value() # chain B
)
Result
Check the first if statement. Did you correctly specify the condition? Expected <code>False</code>, but got <code>True</code>.
No error
Example 4¶
No PEC
Solution code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items():
print(key + " - " + str(value))
Student code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items():
print(key + " - " + str(value))
Student output
b - 2
a - 1
SCT
Ex().check_object('my_dict').has_equal_value()
Ex().check_for_loop().multi(
check_iter().has_equal_value(),
check_body().multi(
set_context('a', 1).has_equal_output(),
set_context('b', 2).has_equal_output()
)
)
Result
Great work!
No error
Example 5¶
No PEC
Solution code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items():
print(key + " - " + str(value))
Student code
my_dict = {'a': 1, 'b': 2}
for k, v in my_dict.items():
print(k + ' - ' + str(v))
Student output
b - 2
a - 1
SCT
Ex().check_object('my_dict').has_equal_value()
Ex().check_for_loop().multi(
check_iter().has_equal_value(),
check_body().multi(
set_context('a', 1).has_equal_output(),
set_context('b', 2).has_equal_output()
)
)
Result
Great work!
No error
Example 6¶
No PEC
Solution code
my_dict = {'a': 1, 'b': 2}
for key, value in my_dict.items():
print(key + " - " + str(value))
Student code
my_dict = {'a': 1, 'b': 2}
for first, second in my_dict.items():
mess = first + ' - ' + str(second)
print(mess)
Student output
b - 2
a - 1
SCT
Ex().check_object('my_dict').has_equal_value()
Ex().check_for_loop().multi(
check_iter().has_equal_value(),
check_body().multi(
set_context('a', 1).has_equal_output(),
set_context('b', 2).has_equal_output()
)
)
Result
Great work!
No error
Example 7¶
No PEC
Solution code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
Student code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
No output
SCT
Ex().check_function_def('shout_echo').test_correct(
multi(
check_call("f('hey', 3)").has_equal_value(),
check_call("f('hi', 2)").has_equal_value(),
check_call("f('hi')").has_equal_value()
),
check_body().set_context('test', 1).multi(
has_equal_value(name = 'echo_word'),
has_equal_value(name = 'shout_words')
)
)
Result
Great work!
No error
Example 8¶
No PEC
Solution code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
Student code
def shout_echo(w, e=1):
ew = w * e
return ew + '!!!'
No output
SCT
Ex().check_function_def('shout_echo').test_correct(
multi(
check_call("f('hey', 3)").has_equal_value(),
check_call("f('hi', 2)").has_equal_value(),
check_call("f('hi')").has_equal_value()
),
check_body().set_context('test', 1).multi(
has_equal_value(name = 'echo_word'),
has_equal_value(name = 'shout_words')
)
)
Result
Great work!
No error
Example 9¶
No PEC
Solution code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
Student code
def shout_echo(a, b=1):
return a * b + '!!!'
No output
SCT
Ex().check_function_def('shout_echo').test_correct(
multi(
check_call("f('hey', 3)").has_equal_value(),
check_call("f('hi', 2)").has_equal_value(),
check_call("f('hi')").has_equal_value()
),
check_body().set_context('test', 1).multi(
has_equal_value(name = 'echo_word'),
has_equal_value(name = 'shout_words')
)
)
Result
Great work!
No error
Example 10¶
No PEC
Solution code
def counter(lst, key):
count = 0
for l in lst:
count += l[key]
return count
Student code
def counter(lst, key):
count = 0
for l in lst:
count += l[key]
return count
No output
SCT
Ex().check_function_def('counter').test_correct(
multi(
check_call("f([{'a': 1}], 'a')").has_equal_value(),
check_call("f([{'b': 1}, {'b': 2}], 'b')").has_equal_value()
),
check_body().set_context([{'a': 1}, {'a': 2}], 'a').set_env(count = 0).check_for_loop().multi(
check_iter().has_equal_value(),
check_body().set_context({'a': 1}).has_equal_value(name = 'count')
)
)
Result
Great work!
No error
test_test_compound_statement.py¶
Example 1¶
No PEC
Solution code
for i in range(3): print(i)
No student code
No output
SCT
test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
The system wants to check the first for loop but hasn't found it.
No error
Example 2¶
No PEC
Solution code
for i in range(3): print(i)
No student code
No output
SCT
Ex().test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
The system wants to check the first for loop but hasn't found it.
No error
Example 3¶
No PEC
Solution code
for i in range(3): print(i)
No student code
No output
SCT
Ex().check_for_loop().multi(check_iter().has_equal_value(), check_body().has_equal_output())
Result
The system wants to check the first for loop but hasn't found it.
No error
Example 4¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(4): pass
No output
SCT
test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Check the first for loop. Did you correctly specify the sequence part? Expected <code>range(0, 3)</code>, but got <code>range(0, 4)</code>.
No error
Example 5¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(4): pass
No output
SCT
Ex().test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Expected something different.
No error
Example 6¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(4): pass
No output
SCT
Ex().check_for_loop().multi(check_iter().has_equal_value(), check_body().has_equal_output())
Result
Check the first for loop. Did you correctly specify the iterable part? Expected <code>range(0, 3)</code>, but got <code>range(0, 4)</code>.
No error
Example 7¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(3): pass
No output
SCT
test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Check the first for loop. Did you correctly specify the body? Expected the output <code>2</code>, but got <code>no printouts</code>.
No error
Example 8¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(3): pass
No output
SCT
Ex().test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Expected something different.
No error
Example 9¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(3): pass
No output
SCT
Ex().check_for_loop().multi(check_iter().has_equal_value(), check_body().has_equal_output())
Result
Check the first for loop. Did you correctly specify the body? Expected the output <code>2</code>, but got <code>no printouts</code>.
No error
Example 10¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(3): print(i)
Student output
0
1
2
SCT
test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Great work!
No error
Example 11¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(3): print(i)
Student output
0
1
2
SCT
Ex().test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Great work!
No error
Example 12¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for i in range(3): print(i)
Student output
0
1
2
SCT
Ex().check_for_loop().multi(check_iter().has_equal_value(), check_body().has_equal_output())
Result
Great work!
No error
Example 13¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for j in range(3): print(j)
Student output
0
1
2
SCT
test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Great work!
No error
Example 14¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for j in range(3): print(j)
Student output
0
1
2
SCT
Ex().test_for_loop(for_iter=lambda: test_expression_result(), body=lambda: test_expression_output())
Result
Great work!
No error
Example 15¶
No PEC
Solution code
for i in range(3): print(i)
Student code
for j in range(3): print(j)
Student output
0
1
2
SCT
Ex().check_for_loop().multi(check_iter().has_equal_value(), check_body().has_equal_output())
Result
Great work!
No error
Example 16¶
No PEC
Solution code
while 3 > 4: print(2)
No student code
No output
SCT
test_while_loop(test = lambda: test_student_typed('3'), body = lambda: test_student_typed('print'))
Result
The system wants to check the first while loop but hasn't found it.
No error
Example 17¶
No PEC
Solution code
while 3 > 4: print(2)
No student code
No output
SCT
Ex().test_while_loop(test = test_student_typed('3'), body = test_student_typed('print'))
Result
The system wants to check the first while loop but hasn't found it.
No error
Example 18¶
No PEC
Solution code
while 3 > 4: print(2)
No student code
No output
SCT
Ex().check_while().multi(check_test().has_code('3'), check_body().has_code('print'))
Result
The system wants to check the first <code>while</code> loop but hasn't found it.
No error
Example 19¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while False: pass
No output
SCT
test_while_loop(test = lambda: test_student_typed('3'), body = lambda: test_student_typed('print'))
Result
Check the first while loop. Did you correctly specify the condition? Could not find the correct pattern in your code.
No error
Example 20¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while False: pass
No output
SCT
Ex().test_while_loop(test = test_student_typed('3'), body = test_student_typed('print'))
Result
Check the first while loop. Did you correctly specify the condition? Could not find the correct pattern in your code.
No error
Example 21¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while False: pass
No output
SCT
Ex().check_while().multi(check_test().has_code('3'), check_body().has_code('print'))
Result
Check the first <code>while</code> loop. Did you correctly specify the condition? Could not find the correct pattern in your code.
No error
Example 22¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while 3 > 4: pass
No output
SCT
test_while_loop(test = lambda: test_student_typed('3'), body = lambda: test_student_typed('print'))
Result
Check the first while loop. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 23¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while 3 > 4: pass
No output
SCT
Ex().test_while_loop(test = test_student_typed('3'), body = test_student_typed('print'))
Result
Check the first while loop. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 24¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while 3 > 4: pass
No output
SCT
Ex().check_while().multi(check_test().has_code('3'), check_body().has_code('print'))
Result
Check the first <code>while</code> loop. Did you correctly specify the body? Could not find the correct pattern in your code.
No error
Example 25¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while 3 > 4: print(2)
No output
SCT
test_while_loop(test = lambda: test_student_typed('3'), body = lambda: test_student_typed('print'))
Result
Great work!
No error
Example 26¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while 3 > 4: print(2)
No output
SCT
Ex().test_while_loop(test = test_student_typed('3'), body = test_student_typed('print'))
Result
Great work!
No error
Example 27¶
No PEC
Solution code
while 3 > 4: print(2)
Student code
while 3 > 4: print(2)
No output
SCT
Ex().check_while().multi(check_test().has_code('3'), check_body().has_code('print'))
Result
Great work!
No error
test_highlighting.py¶
Example 1¶
No PEC
Solution code
round(2.345, 2)
Student code
round(1.234, 2)
No output
SCT
Ex().check_function("round").check_args("number").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>2.345</code>, but got <code>1.234</code>.
No error
Example 2¶
No PEC
Solution code
round(2.345, 2)
Student code
round(1.234, 2)
No output
SCT
Ex().disable_highlighting().check_function("round").check_args("number").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>2.345</code>, but got <code>1.234</code>.
No error
Example 3¶
No PEC
Solution code
round(2.345, 2)
Student code
round(1.234, 2)
No output
SCT
Ex().check_function("round").disable_highlighting().check_args("number").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>2.345</code>, but got <code>1.234</code>.
No error
Example 4¶
No PEC
Solution code
round(2.345, 2)
Student code
round(1.234, 2)
No output
SCT
Ex().check_function("round").check_args("number").disable_highlighting().has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>2.345</code>, but got <code>1.234</code>.
No error
Example 5¶
No PEC
Solution code
round(1)
round(2)
Student code
round(1)
round(3)
No output
SCT
Ex().check_function("round", index=0).check_args("number").has_equal_value()
Ex().check_function("round", index=1).check_args("number").has_equal_value()
Result
Check your second call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>2</code>, but got <code>3</code>.
No error
Example 6¶
No PEC
Solution code
round(1)
round(2)
Student code
round(3)
round(2)
No output
SCT
Ex().check_function("round", index=0).check_args("number").has_equal_value()
Ex().check_function("round", index=1).check_args("number").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>1</code>, but got <code>3</code>.
No error
Example 7¶
No PEC
Solution code
round(1)
round(2)
Student code
round(3)
round(1)
No output
SCT
Ex().check_function("round", index=0).check_args("number").has_equal_value()
Ex().check_function("round", index=1).check_args("number").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>1</code>, but got <code>3</code>.
No error
Example 8¶
No PEC
Solution code
round(1)
round(2)
Student code
round(2)
round(3)
No output
SCT
Ex().check_function("round", index=0).check_args("number").has_equal_value()
Ex().check_function("round", index=1).check_args("number").has_equal_value()
Result
Check your call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>1</code>, but got <code>2</code>.
No error
Example 9¶
No PEC
Solution code
round(1)
round(2)
Student code
round(1)
round(3)
No output
SCT
Ex().check_function("round", index=1).check_args("number").has_equal_value()
Result
Check your second call of <code>round()</code>. Did you correctly specify the argument <code>number</code>? Expected <code>2</code>, but got <code>3</code>.
No error
test_check_function.py¶
Example 1¶
PEC
def my_fun(a, b): pass
Solution code
my_fun(1, 2)
Student code
my_fun(x = 2)
No output
SCT
Ex().check_function('my_fun')
Result
Have you specified the arguments for <code>my_fun()</code> using the right syntax?
Error
my_fun() got an unexpected keyword argument 'x'
Example 2¶
No PEC
Solution code
def my_func(a): return my_func_in_return(b)
Student code
def my_func(a): return my_func_in_return(b)
No output
SCT
Ex().check_function_def('my_func').check_body().check_function('my_func_in_return', signature=False)
Result
Great work!
No error
Example 3¶
No PEC
Solution code
0 < len([])
Student code
0 < len([])
No output
SCT
Ex().check_function('len')
Result
Great work!
No error
Example 4¶
No PEC
Solution code
len([]) < 3
Student code
len([]) < 3
No output
SCT
Ex().check_function('len')
Result
Great work!
No error
Example 5¶
No PEC
Solution code
0 < len([]) < 3
Student code
0 < len([]) < 3
No output
SCT
Ex().check_function('len')
Result
Great work!
No error
test_test_with.py¶
Example 1¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(1, body = lambda: [test_function('print', index = i + 1) for i in range(3)])
Result
Check your third call of <code>print()</code>. Did you correctly specify the first argument? Expected something different.
No error
Example 2¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(2, body = lambda: test_for_loop(1, body = lambda: test_if_else(1, body = lambda: test_function('print'))))
Result
Great work!
No error
Example 3¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(1, body = [test_function('print', index = i + 1) for i in range(3)])
Result
Check your third call of <code>print()</code>. Did you correctly specify the first argument? Expected something different.
No error
Example 4¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(2, body = test_for_loop(1, body = test_if_else(1, body = test_function('print'))))
Result
Great work!
No error
Example 5¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
for_test = test_for_loop(1, body = test_if_else(1, body = test_function('print')))
Ex().check_with(1).check_body().with_context(for_test)
Result
Great work!
No error
Example 6¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
Ex().check_with(0).check_body().with_context([test_function('print', index = i+1) for i in range(3)])
Result
Check your third call of <code>print()</code>. Did you correctly specify the first argument? Expected something different.
No error
Example 7¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
# since the print func is being tested w/o SCTs setting any variables, don't need with_context
for_test = test_for_loop(1, body = test_if_else(1, body = test_function('print')))
Ex().check_with(1).check_body().multi(for_test)
Result
Great work!
No error
Example 8¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file, open('moby_dick.txt'):
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as not_file:
for i, row in enumerate(not_file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(1, context_vals=True)
Result
Check the first <code>with</code> statement. Make sure to use the correct number of context variables. It seems you defined too many.
No error
Example 9¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file, open('moby_dick.txt'):
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as not_file:
for i, row in enumerate(not_file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(2, context_vals=True)
Result
Check the second <code>with</code> statement. Did you correctly specify the first context? Make sure to use the correct context variable names. Was expecting <code>file</code> but got <code>not_file</code>.
No error
Example 10¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
from urllib.request import urlretrieve; urlretrieve('https://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'not_moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file, open('moby_dick.txt'):
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file, open('not_moby_dick.txt') as not_file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as not_file, open('moby_dick.txt') as file:
for i, row in enumerate(not_file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(1, context_tests=lambda: test_function('open'))
Result
Great work!
No error
Example 11¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
from urllib.request import urlretrieve; urlretrieve('https://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'not_moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file, open('moby_dick.txt'):
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file, open('not_moby_dick.txt') as not_file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as not_file, open('moby_dick.txt') as file:
for i, row in enumerate(not_file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(1, context_tests=[
lambda: test_function('open'),
lambda: test_function('open')])
Result
Check the first <code>with</code> statement. Make sure to use the correct number of context variables. It seems you defined too little.
No error
Example 12¶
PEC
from urllib.request import urlretrieve; urlretrieve('http://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'moby_dick.txt')
from urllib.request import urlretrieve; urlretrieve('https://s3.amazonaws.com/assets.datacamp.com/production/course_998/datasets/moby_opens.txt', 'not_moby_dick.txt')
Solution code
# Read & print the first 3 lines
with open('moby_dick.txt') as file, open('moby_dick.txt'):
print(file.readline())
print(file.readline())
print(file.readline())
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as file, open('not_moby_dick.txt') as not_file:
for i, row in enumerate(file):
if i in I:
print(row)
Student code
# Read & print the first 3 lines
with open('moby_dick.txt') as file:
print(file.readline())
print(file.readline())
print('test')
# The rows that you wish to print
I = [0,1,3,5,6,7,8,9]
# Print out these rows
with open('moby_dick.txt') as not_file, open('moby_dick.txt') as file:
for i, row in enumerate(not_file):
if i in I:
print(row)
Student output
CHAPTER 1. Loomings.
test
CHAPTER 1. Loomings.
little or no money in my purse, and nothing particular to interest me on
the world. It is a way I have of driving off the spleen and regulating
the circulation. Whenever I find myself growing grim about the mouth;
whenever it is a damp, drizzly November in my soul; whenever I find
myself involuntarily pausing before coffin warehouses, and bringing up
the rear of every funeral I meet; and especially whenever my hypos get
SCT
test_with(2, context_tests=[
lambda: test_function('open'),
lambda: test_function('open')])
Result
Check your call of <code>open()</code>. Did you correctly specify the first argument? Expected <code>not_moby_dick.txt</code>, but got <code>moby_dick.txt</code>.
No error
Example 13¶
PEC
class A:
def __enter__(self): return [1,2, 3]
def __exit__(self, *args, **kwargs): return
Solution code
with A() as (one, *others):
print(one)
print(others)
Student code
with A() as (one, *others):
print(one)
print(others)
Student output
1
[2, 3]
SCT
test_with(1, body=[test_function('print'), test_function('print')])
Result
Great work!
No error
Example 14¶
PEC
from io import StringIO
Solution code
with StringIO() as f1, StringIO() as f2: pass
Student code
with StringIO() as f1, StringIO() as f2: pass
No output
SCT
Ex().check_with(0).has_context()
Result
Great work!
No error
Example 15¶
PEC
from io import StringIO
Solution code
with StringIO() as f1, StringIO() as f2: pass
Student code
with StringIO() as f1: pass
No output
SCT
Ex().check_with(0).has_context()
Result
Check the first <code>with</code> statement. Are you sure you defined the second context?
No error
Example 16¶
PEC
from io import StringIO
Solution code
with StringIO() as f1, StringIO() as f2: pass
Student code
with StringIO() as f3, StringIO() as f4: pass
No output
SCT
Ex().check_with(0).has_context(exact_names=True)
Result
Check the first <code>with</code> statement. Did you correctly specify the first context? Make sure to use the correct context variable names. Was expecting <code>f1</code> but got <code>f3</code>.
No error
Example 17¶
PEC
from io import StringIO
Solution code
with StringIO() as f1, StringIO() as f2: pass
Student code
with StringIO() as f1, StringIO() as f2: pass
No output
SCT
Ex().check_with(0).check_context(0).has_context()
Result
Great work!
No error
Example 18¶
PEC
from io import StringIO
Solution code
with StringIO() as f1, StringIO() as f2: pass
Student code
with StringIO() as f3: pass
No output
SCT
Ex().check_with(0).check_context(0).has_context(exact_names=True)
Result
Check the first <code>with</code> statement. Did you correctly specify the first context?
No error
test_set_context.py¶
Example 1¶
No PEC
Solution code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
Student code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
No output
SCT
Ex().check_function_def('shout_echo').check_body().set_context('test', 1).has_equal_value(name = 'shout_words')
Result
Great work!
No error
Example 2¶
No PEC
Solution code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
Student code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
No output
SCT
Ex().check_function_def('shout_echo').check_body().set_context(word1 = 'test', echo = 1).has_equal_value(name = 'shout_words')
Result
Great work!
No error
Example 3¶
No PEC
Solution code
def shout_echo(w, echo=1):
echo_word = w * echo
shout_words = echo_word + '!!!'
return shout_words
Student code
def shout_echo(word1, echo=1):
echo_word = word1 * echo
shout_words = echo_word + '!!!'
return shout_words
No output
SCT
Ex().check_function_def('shout_echo').check_body().set_context('test', 1).has_equal_value(name = 'shout_words')
Result
Great work!
No error
Example 4¶
No PEC
Solution code
x = { m:len(m) for m in ['a', 'b', 'c'] }
Student code
x = { m:len(m) for m in ['a', 'b', 'c'] }
No output
SCT
Ex().check_dict_comp().check_key().set_context('a').has_equal_value()
Result
Great work!
No error
Example 5¶
No PEC
Solution code
x = { m:len(m) for m in ['a', 'b', 'c'] }
Student code
x = { m:len(m) for m in ['a', 'b', 'c'] }
No output
SCT
Ex().check_dict_comp().check_key().set_context(m = 'a').has_equal_value()
Result
Great work!
No error
Example 6¶
No PEC
Solution code
x = { n:len(n) for n in ['a', 'b', 'c'] }
Student code
x = { m:len(m) for m in ['a', 'b', 'c'] }
No output
SCT
Ex().check_dict_comp().check_key().set_context('a').has_equal_value()
Result
Great work!
No error
Example 7¶
No PEC
Solution code
x = { m*2:len(m) for m in ['a', 'b', 'c'] }
Student code
x = { m:len(m) for m in ['a', 'b', 'c'] }
No output
SCT
Ex().check_dict_comp().check_key().set_context('a').has_equal_value()
Result
Check the first dictionary comprehension. Did you correctly specify the key part? Expected <code>aa</code>, but got <code>a</code>.
No error
test_has_expr.py¶
Example 1¶
No PEC
Solution code
a = 0
for i in range(0): a = a + 1
Student code
a = 0
for i in range(0): pass
No output
SCT
test_for_loop(body = test_object_after_expression('a'))
Result
Check the first for loop. Did you correctly specify the body? Are you sure you assigned the correct value to <code>a</code>?
No error
Example 2¶
No PEC
Solution code
a = 0
for i in range(0): a = a + 1
Student code
a = 0
for i in range(0): a = a - 1
No output
SCT
test_for_loop(body = test_object_after_expression('a'))
Result
Check the first for loop. Did you correctly specify the body? Are you sure you assigned the correct value to <code>a</code>?
No error
Example 3¶
No PEC
Solution code
a = 0
for i in range(0): a = a + 1
Student code
a = 0
for i in range(0): a = a + 1
No output
SCT
test_for_loop(body = test_object_after_expression('a'))
Result
Great work!
No error
test_v2_only.py¶
Example 1¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
test_object('x')
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 2¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
Ex().test_object('x')
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 3¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
test_function('round')
Result
Check your call of <code>round()</code>. Did you correctly specify the first argument? Expected <code>5</code>, but got <code>4</code>.
No error
Example 4¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 5¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
Ex() >> check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 6¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
x = check_object('x').has_equal_value(); Ex() >> x
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 7¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
Ex().check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 8¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
Ex() >> check_object('x').has_equal_value()
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 9¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
Ex().check_or(check_object('x').has_equal_value(), check_object('x').has_equal_value())
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
Example 10¶
No PEC
Solution code
x = round(5)
Student code
x = round(4)
No output
SCT
x = check_object('x').has_equal_value(); Ex() >> x
Result
Did you correctly define the variable <code>x</code>? Expected <code>5</code>, but got <code>4</code>.
No error
test_has_chosen.py¶
Example 1¶
No PEC
No solution code
Student code
selected_option = 1
No output
SCT
test_mc(2, ['a', 'b', 'c'])
Result
a
No error
Example 2¶
No PEC
No solution code
Student code
selected_option = 1
No output
SCT
Ex().has_chosen(2, ['a', 'b', 'c'])
Result
a
No error
Example 3¶
No PEC
No solution code
Student code
selected_option = 2
No output
SCT
test_mc(2, ['a', 'b', 'c'])
Result
b
No error
Example 4¶
No PEC
No solution code
Student code
selected_option = 2
No output
SCT
Ex().has_chosen(2, ['a', 'b', 'c'])
Result
b
No error
Example 5¶
No PEC
No solution code
Student code
selected_option = 3
No output
SCT
test_mc(2, ['a', 'b', 'c'])
Result
c
No error
Example 6¶
No PEC
No solution code
Student code
selected_option = 3
No output
SCT
Ex().has_chosen(2, ['a', 'b', 'c'])
Result
c
No error
test_has_no_error.py¶
Example 1¶
No PEC
No solution code
Student code
c
No output
SCT
Ex().has_no_error()
Result
Have a look at the console: your code contains an error. Fix it and try again!
Error
name 'c' is not defined
Example 2¶
No PEC
No solution code
Student code
a = 3
No output
SCT
Ex().has_no_error()
Result
Great work!
No error
test_spec.py¶
Example 1¶
No PEC
Solution code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
Student code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
No output
SCT
list_comp = F().check_list_comp(0).check_body().set_context(ii=2).has_equal_value('unequal')
Ex().check_list_comp(0).check_body().set_context(aa=2).multi(list_comp)
Result
Great work!
No error
Example 2¶
No PEC
Solution code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
Student code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
No output
SCT
list_comp = check_list_comp(0).check_body().set_context(ii=2).has_equal_value('unequal')
Ex().check_list_comp(0).check_body().set_context(aa=2).multi(list_comp)
Result
Great work!
No error
Example 3¶
No PEC
Solution code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
Student code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
No output
SCT
# funky, but we're testing nested check functions!
multi_test = multi(check_list_comp(0).check_body().set_context(aa=2).has_equal_value('badbody'))
Ex().multi(multi_test)
Result
Great work!
No error
Example 4¶
No PEC
Solution code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
Student code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
No output
SCT
list_comp = F().check_list_comp(0).check_body().set_context(ii=2).has_equal_value('unequal')
Ex().check_list_comp(0).check_body().set_context(aa=2).multi(list_comp)
Ex().check_list_comp(1).check_body().set_context(bb=4).multi(list_comp)
Result
Great work!
No error
Example 5¶
No PEC
Solution code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
Student code
[[ii+1 for ii in range(aa)] for aa in range(2)]
[[ii*2 for ii in range(bb)] for bb in range(1,3)]
No output
SCT
eq_test = F().check_list_comp(0).check_body().set_context(1).has_equal_value
Ex().multi(eq_test('unequal'))
Result
Great work!
No error
Example 6¶
No PEC
Solution code
[aa+1 for aa in range(2)]
Student code
[aa+1 for aa in range(2)]
No output
SCT
te = test_expression_result(extra_env={'aa':2}, incorrect_msg='unequal')
Ex().multi(test_list_comp(body=te)) # spec 1 inside multi
Ex().check_list_comp(0).check_body().multi(te) # half of each spec
Ex().check_list_comp(0).check_body().set_context(aa=2).has_equal_value('unequal') # full spec 2
test_list_comp(body=te) # full spec 1
Result
Great work!
No error
Example 7¶
No PEC
Solution code
[aa+1 for aa in range(2)]
Student code
for aa in range(3): aa
No output
SCT
test_list_comp(body=test_expression_result(expr_code = 'aa', incorrect_msg='unequal'))
Ex().check_list_comp(0).check_body().multi(test_expression_result(incorrect_msg='unequal'))
Ex().check_list_comp(0).check_body().has_equal_value('unequal')
Result
The system wants to check the first list comprehension but hasn't found it.
No error
Example 8¶
No PEC
Solution code
[aa+1 for aa in range(2)]
Student code
[aa for aa in range(2)]
No output
SCT
Ex().test_list_comp(body=test_expression_result(extra_env={'aa': 2}, incorrect_msg = 'spec1'))
Ex().check_list_comp(0).check_body().set_context(aa=2).has_equal_value('spec2')
Result
spec1
No error
Example 9¶
No PEC
Solution code
[aa+1 for aa in range(2)]
Student code
[aa+1 for aa in range(2)]
No output
SCT
test_body = F().check_body().set_context(aa=2).has_equal_value('wrong')
Ex().check_list_comp(0).multi(F().multi(test_body))
Result
Great work!
No error
Example 10¶
No PEC
Solution code
[aa+1 for aa in range(2)]
Student code
[aa+1 for aa in range(2)]
No output
SCT
test_body = F().check_list_comp(0).check_body().set_context(aa=2).has_equal_value('wrong')
Ex().check_list_comp(0).multi(F().check_body().set_context(aa=2).has_equal_value('wrong'))
Result
Great work!
No error
Example 11¶
No PEC
Solution code
[aa+1 for aa in range(2)]
Student code
[aa+1 for aa in range(2)]
No output
SCT
Ex().check_list_comp(0).check_body() .multi(set_context(aa=i).has_equal_value('wrong') for i in range(2))
Result
Great work!
No error
Example 13¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(a = 'a') .keys()
No output
SCT
Ex().has_equal_ast()
Result
Great work!
No error
Example 14¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(A = 'a').keys(somearg = 2)
No output
SCT
Ex().has_equal_ast()
Result
Expected <code>dict(a = "a").keys()</code>, but got <code>dict(A = 'a').keys(somearg = 2)</code>.
No error
Example 15¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(a = 'a') .keys()
No output
SCT
Ex().check_function('dict', 0, signature=False).has_equal_ast()
Result
Great work!
No error
Example 16¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(A = 'a').keys(somearg = 2)
No output
SCT
Ex().check_function('dict', 0, signature=False).has_equal_ast()
Result
Check your call of <code>dict()</code>. Expected <code>dict(a = "a")</code>, but got <code>dict(A = 'a')</code>.
No error
Example 17¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(a = 'a') .keys()
No output
SCT
Ex().has_equal_ast(code = 'dict(a = "a").keys()', incorrect_msg = 'icr')
Result
Great work!
No error
Example 18¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(A = 'a').keys(somearg = 2)
No output
SCT
Ex().has_equal_ast(code = 'dict(a = "a").keys()', incorrect_msg = 'icr')
Result
icr
No error
Example 19¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(a = 'a').keys()
print('extra')
Student output
extra
SCT
Ex().has_equal_ast(exact=False)
Result
Great work!
No error
Example 20¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(A = 'a').keys(somearg = 2)
No output
SCT
Ex().has_equal_ast(exact=False)
Result
Expected <code>dict(a = "a").keys()</code>, but got <code>dict(A = 'a').keys(somearg = 2)</code>.
No error
Example 21¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(a = 'a') .keys()
No output
SCT
Ex().has_equal_ast(code = 'dict(a = "a")', exact=False, incorrect_msg = 'icr')
Result
Great work!
No error
Example 22¶
No PEC
Solution code
dict(a = "a").keys()
Student code
dict(A = 'a').keys(somearg = 2)
No output
SCT
Ex().has_equal_ast(code = 'dict(a = "a")', exact=False, incorrect_msg = 'icr')
Result
icr
No error
Example 23¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).override("""1 if False else 2""").has_equal_ast()
Result
Great work!
No error
Example 24¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the first if expression. Expected `<code>, but got</code>1 if False else 2`.
No error
Example 25¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 26¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).check_body().override("""1 if False else 2""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 27¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).check_test().override("""False""").has_equal_ast()
Result
Great work!
No error
Example 28¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).check_test().override("""1 if False else 2""").has_equal_ast()
Result
Did you correctly specify the condition? Expected `<code>, but got</code>False`.
No error
Example 29¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).check_orelse().override("""2""").has_equal_ast()
Result
Great work!
No error
Example 30¶
No PEC
Solution code
1 if False else 2
Student code
1 if False else 2
No output
SCT
Ex().check_if_exp(0).check_orelse().override("""1 if False else 2""").has_equal_ast()
Result
Did you correctly specify the else part? Expected `<code>, but got</code>2`.
No error
Example 31¶
No PEC
Solution code
[1 for i in range(3)]
Student code
[1 for i in range(3)]
No output
SCT
Ex().check_list_comp(0).override("""[1 for i in range(3)]""").has_equal_ast()
Result
Great work!
No error
Example 32¶
No PEC
Solution code
[1 for i in range(3)]
Student code
[1 for i in range(3)]
No output
SCT
Ex().check_list_comp(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the first list comprehension. Expected `<code>, but got</code>[1 for i in range(3)]`.
No error
Example 33¶
No PEC
Solution code
[1 for i in range(3)]
Student code
[1 for i in range(3)]
No output
SCT
Ex().check_list_comp(0).check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 34¶
No PEC
Solution code
[1 for i in range(3)]
Student code
[1 for i in range(3)]
No output
SCT
Ex().check_list_comp(0).check_body().override("""[1 for i in range(3)]""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 35¶
No PEC
Solution code
[1 for i in range(3)]
Student code
[1 for i in range(3)]
No output
SCT
Ex().check_list_comp(0).check_iter().override("""range(3)""").has_equal_ast()
Result
Great work!
No error
Example 36¶
No PEC
Solution code
[1 for i in range(3)]
Student code
[1 for i in range(3)]
No output
SCT
Ex().check_list_comp(0).check_iter().override("""[1 for i in range(3)]""").has_equal_ast()
Result
Did you correctly specify the iterable part? Expected `<code>, but got</code>range(3)`.
No error
Example 37¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).override("""{ 3: 4 for i in range(3) }""").has_equal_ast()
Result
Great work!
No error
Example 38¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the first dictionary comprehension. Expected `<code>, but got</code>{ 3: 4 for i in range(3) }`.
No error
Example 39¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).check_key().override("""3""").has_equal_ast()
Result
Great work!
No error
Example 40¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).check_key().override("""{ 3: 4 for i in range(3) }""").has_equal_ast()
Result
Did you correctly specify the key part? Expected `<code>, but got</code>3`.
No error
Example 41¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).check_value().override("""4""").has_equal_ast()
Result
Great work!
No error
Example 42¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).check_value().override("""{ 3: 4 for i in range(3) }""").has_equal_ast()
Result
Did you correctly specify the value part? Expected `<code>, but got</code>4`.
No error
Example 43¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).check_iter().override("""range(3)""").has_equal_ast()
Result
Great work!
No error
Example 44¶
No PEC
Solution code
{ 3: 4 for i in range(3) }
Student code
{ 3: 4 for i in range(3) }
No output
SCT
Ex().check_dict_comp(0).check_iter().override("""{ 3: 4 for i in range(3) }""").has_equal_ast()
Result
Did you correctly specify the iterable part? Expected `<code>, but got</code>range(3)`.
No error
Example 45¶
No PEC
Solution code
for i in range(3): 1
Student code
for i in range(3): 1
No output
SCT
Ex().check_for_loop(0).override("""for i in range(3): 1""").has_equal_ast()
Result
Great work!
No error
Example 46¶
No PEC
Solution code
for i in range(3): 1
Student code
for i in range(3): 1
No output
SCT
Ex().check_for_loop(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the first for loop. Expected `<code>, but got</code>for i in range(3): 1`.
No error
Example 47¶
No PEC
Solution code
for i in range(3): 1
Student code
for i in range(3): 1
No output
SCT
Ex().check_for_loop(0).check_iter().override("""range(3)""").has_equal_ast()
Result
Great work!
No error
Example 48¶
No PEC
Solution code
for i in range(3): 1
Student code
for i in range(3): 1
No output
SCT
Ex().check_for_loop(0).check_iter().override("""for i in range(3): 1""").has_equal_ast()
Result
Did you correctly specify the iterable part? Expected `<code>, but got</code>range(3)`.
No error
Example 49¶
No PEC
Solution code
for i in range(3): 1
Student code
for i in range(3): 1
No output
SCT
Ex().check_for_loop(0).check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 50¶
No PEC
Solution code
for i in range(3): 1
Student code
for i in range(3): 1
No output
SCT
Ex().check_for_loop(0).check_body().override("""for i in range(3): 1""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 51¶
No PEC
Solution code
while False: 1
Student code
while False: 1
No output
SCT
Ex().check_while(0).override("""while False: 1""").has_equal_ast()
Result
Great work!
No error
Example 52¶
No PEC
Solution code
while False: 1
Student code
while False: 1
No output
SCT
Ex().check_while(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the first <code>while</code> loop. Expected `<code>, but got</code>while False: 1`.
No error
Example 53¶
No PEC
Solution code
while False: 1
Student code
while False: 1
No output
SCT
Ex().check_while(0).check_test().override("""False""").has_equal_ast()
Result
Great work!
No error
Example 54¶
No PEC
Solution code
while False: 1
Student code
while False: 1
No output
SCT
Ex().check_while(0).check_test().override("""while False: 1""").has_equal_ast()
Result
Did you correctly specify the condition? Expected `<code>, but got</code>False`.
No error
Example 55¶
No PEC
Solution code
while False: 1
Student code
while False: 1
No output
SCT
Ex().check_while(0).check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 56¶
No PEC
Solution code
while False: 1
Student code
while False: 1
No output
SCT
Ex().check_while(0).check_body().override("""while False: 1""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 57¶
No PEC
Solution code
try: 1
except: pass
else: 2
Student code
try: 1
except: pass
else: 2
No output
SCT
Ex().check_try_except(0).override("""try: 1
except: pass
else: 2""").has_equal_ast()
Result
Great work!
No error
Example 58¶
No PEC
Solution code
try: 1
except: pass
else: 2
Student code
try: 1
except: pass
else: 2
No output
SCT
Ex().check_try_except(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
<p>Check the first try statement. Expected `<code>, but got</code>try: 1
except: pass
else: 2`.</p>
No error
Example 59¶
No PEC
Solution code
try: 1
except: pass
else: 2
Student code
try: 1
except: pass
else: 2
No output
SCT
Ex().check_try_except(0).check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 60¶
No PEC
Solution code
try: 1
except: pass
else: 2
Student code
try: 1
except: pass
else: 2
No output
SCT
Ex().check_try_except(0).check_body().override("""try: 1
except: pass
else: 2""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 61¶
No PEC
Solution code
try: 1
except: pass
else: 2
Student code
try: 1
except: pass
else: 2
No output
SCT
Ex().check_try_except(0).check_orelse().override("""2""").has_equal_ast()
Result
Great work!
No error
Example 62¶
No PEC
Solution code
try: 1
except: pass
else: 2
Student code
try: 1
except: pass
else: 2
No output
SCT
Ex().check_try_except(0).check_orelse().override("""try: 1
except: pass
else: 2""").has_equal_ast()
Result
Did you correctly specify the else part? Expected `<code>, but got</code>2`.
No error
Example 63¶
No PEC
Solution code
lambda a=(1,2,3): 1
Student code
lambda a=(1,2,3): 1
No output
SCT
Ex().check_lambda_function(0).override("""lambda a=(1,2,3): 1""").has_equal_ast()
Result
Great work!
No error
Example 64¶
No PEC
Solution code
lambda a=(1,2,3): 1
Student code
lambda a=(1,2,3): 1
No output
SCT
Ex().check_lambda_function(0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the first lambda function. Expected `<code>, but got</code>lambda a=(1,2,3): 1`.
No error
Example 65¶
No PEC
Solution code
lambda a=(1,2,3): 1
Student code
lambda a=(1,2,3): 1
No output
SCT
Ex().check_lambda_function(0).check_args(0).override("""(1,2,3)""").has_equal_ast()
Result
Great work!
No error
Example 66¶
No PEC
Solution code
lambda a=(1,2,3): 1
Student code
lambda a=(1,2,3): 1
No output
SCT
Ex().check_lambda_function(0).check_args(0).override("""lambda a=(1,2,3): 1""").has_equal_ast()
Result
Did you correctly specify the first argument? Expected `<code>, but got</code>1,2,3`.
No error
Example 67¶
No PEC
Solution code
lambda a=(1,2,3): 1
Student code
lambda a=(1,2,3): 1
No output
SCT
Ex().check_lambda_function(0).check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 68¶
No PEC
Solution code
lambda a=(1,2,3): 1
Student code
lambda a=(1,2,3): 1
No output
SCT
Ex().check_lambda_function(0).check_body().override("""lambda a=(1,2,3): 1""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 69¶
No PEC
Solution code
def sum(a=(1,2,3)): 1
Student code
def sum(a=(1,2,3)): 1
No output
SCT
Ex().check_function_def('sum').override("""def sum(a=(1,2,3)): 1""").has_equal_ast()
Result
Great work!
No error
Example 70¶
No PEC
Solution code
def sum(a=(1,2,3)): 1
Student code
def sum(a=(1,2,3)): 1
No output
SCT
Ex().check_function_def('sum').override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check the definition of <code>sum()</code>. Expected `<code>, but got</code>def sum(a=(1,2,3)): 1`.
No error
Example 71¶
No PEC
Solution code
def sum(a=(1,2,3)): 1
Student code
def sum(a=(1,2,3)): 1
No output
SCT
Ex().check_function_def('sum').check_args(0).override("""(1,2,3)""").has_equal_ast()
Result
Great work!
No error
Example 72¶
No PEC
Solution code
def sum(a=(1,2,3)): 1
Student code
def sum(a=(1,2,3)): 1
No output
SCT
Ex().check_function_def('sum').check_args(0).override("""def sum(a=(1,2,3)): 1""").has_equal_ast()
Result
Did you correctly specify the first argument? Expected `<code>, but got</code>1,2,3`.
No error
Example 73¶
No PEC
Solution code
def sum(a=(1,2,3)): 1
Student code
def sum(a=(1,2,3)): 1
No output
SCT
Ex().check_function_def('sum').check_body().override("""1""").has_equal_ast()
Result
Great work!
No error
Example 74¶
No PEC
Solution code
def sum(a=(1,2,3)): 1
Student code
def sum(a=(1,2,3)): 1
No output
SCT
Ex().check_function_def('sum').check_body().override("""def sum(a=(1,2,3)): 1""").has_equal_ast()
Result
Did you correctly specify the body? Expected `<code>, but got</code>1`.
No error
Example 75¶
No PEC
Solution code
sum((1,2,3))
Student code
sum((1,2,3))
No output
SCT
Ex().check_function('sum', 0).override("""sum((1,2,3))""").has_equal_ast()
Result
Great work!
No error
Example 76¶
No PEC
Solution code
sum((1,2,3))
Student code
sum((1,2,3))
No output
SCT
Ex().check_function('sum', 0).override("""'WRONG ANSWER'""").has_equal_ast()
Result
Check your call of <code>sum()</code>. Expected `<code>, but got</code>sum((1,2,3))`.
No error
Example 77¶
No PEC
Solution code
sum((1,2,3))
Student code
sum((1,2,3))
No output
SCT
Ex().check_function('sum', 0).check_args(0).override("""(1,2,3)""").has_equal_ast()
Result
Great work!
No error
Example 78¶
No PEC
Solution code
sum((1,2,3))
Student code
sum((1,2,3))
No output
SCT
Ex().check_function('sum', 0).check_args(0).override("""sum((1,2,3))""").has_equal_ast()
Result
Did you correctly specify the first argument? Expected `<code>, but got</code>1,2,3`.
No error
test_debug.py¶
Example 1¶
No PEC
Solution code
x = 123
Student code
x = 123
No output
SCT
success_msg('great')
Result
great
No error
Example 2¶
No PEC
Solution code
# Example, do not modify!
print(5 / 8)
# Put code below here
print(7 + 10)
Student code
# Example, do not modify!
print(5 / 8)
# Put code below here
print(7 + 10)
Student output
0.625
17
SCT
Ex().has_printout(1, not_printed_msg = "__JINJA__:Have you used `{{sol_call}}` to print out the sum of 7 and 10?")
success_msg("Great! On to the next one!")
Result
Great! On to the next one!
No error
test_check_try_except.py¶
Example 1¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
No student code
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
The system wants to check the first try statement but hasn't found it.
No error
Example 2¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerrors'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Did you correctly specify the <code>TypeError</code> <code>except</code> block? Are you sure you assigned the correct value to <code>x</code>?
No error
Example 3¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the <code>ValueError</code> <code>except</code> block?
No error
Example 4¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerrors'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Did you correctly specify the <code>ValueError</code> <code>except</code> block? Are you sure you assigned the correct value to <code>x</code>?
No error
Example 5¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the <code>ZeroDivisionError</code> <code>except</code> block?
No error
Example 6¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except ZeroDivisionError as e:
x = 'test'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Did you correctly specify the <code>ZeroDivisionError</code> <code>except</code> block? Are you sure you assigned the correct value to <code>x</code>?
No error
Example 7¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except ZeroDivisionError as e:
x = e
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the <code>IOError</code> <code>except</code> block?
No error
Example 8¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = 'test'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Did you correctly specify the <code>ZeroDivisionError</code> <code>except</code> block? Are you sure you assigned the correct value to <code>x</code>?
No error
Example 9¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the <code>CParserError</code> <code>except</code> block?
No error
Example 10¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError as e:
x = 'CParserError'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the <code>all</code> <code>except</code> block?
No error
Example 11¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError as e:
x = 'CParserError'
except :
x = 'someerrors'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Did you correctly specify the <code>all</code> <code>except</code> block? Are you sure you assigned the correct value to <code>x</code>?
No error
Example 12¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError as e:
x = 'CParserError'
except :
x = 'someerror'
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the else part?
No error
Example 13¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError as e:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = False
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Did you correctly specify the else part? Are you sure you assigned the correct value to <code>passed</code>?
No error
Example 14¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError as e:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
No output
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check the first try statement. Are you sure you defined the finally part?
No error
Example 15¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError as e:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('donessss')
Student output
donessss
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Check your call of <code>print()</code>. Did you correctly specify the first argument? Expected <code>done</code>, but got <code>donessss</code>.
No error
Example 16¶
PEC
import numpy as np
Solution code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student code
try:
x = max([1, 2, 'a'])
except TypeError as e:
x = 'typeerror'
except __builtin__.ValueError:
x = 'valueerror'
except (ZeroDivisionError, IOError) as e:
x = e
except pd.io.common.CParserError:
x = 'CParserError'
except :
x = 'someerror'
else :
passed = True
finally:
print('done')
Student output
done
SCT
Ex().check_try_except().multi(
check_body().check_function('max', signature = False).check_args(0).has_equal_value(),
check_handlers('TypeError').has_equal_value(name = 'x'),
check_handlers('ValueError').has_equal_value(name = 'x'),
check_handlers('ZeroDivisionError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('IOError').set_context(e = 'anerror').has_equal_value(name = 'x'),
check_handlers('CParserError').has_equal_value(name = 'x'),
check_handlers('all').has_equal_value(name = 'x'),
check_orelse().has_equal_value(name = 'passed'),
check_finalbody().check_function('print').check_args(0).has_equal_value()
)
Result
Great work!
No error
test_test_object_accessed.py¶
Example 1¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792c4c8288>
2.718281828459045
SCT
test_object_accessed("arr")
Result
Great work!
No error
Example 2¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792c4c8288>
2.718281828459045
SCT
test_object_accessed("ar")
Result
Have you accessed <code>ar</code>?
No error
Example 3¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f793e8d9e88>
2.718281828459045
SCT
test_object_accessed("arr", times=2)
Result
Great work!
No error
Example 4¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f793e8d9e88>
2.718281828459045
SCT
test_object_accessed("arr", times=3)
Result
Have you accessed <code>arr</code> at least three times?
No error
Example 5¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f793e8d9f48>
2.718281828459045
SCT
test_object_accessed("arr", times=3, not_accessed_msg="silly")
Result
silly
No error
Example 6¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f793e8d9f48>
2.718281828459045
SCT
test_object_accessed("arr.shape")
Result
Great work!
No error
Example 7¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792c4c84c8>
2.718281828459045
SCT
test_object_accessed("arr.shape", times=2)
Result
Have you accessed <code>arr.shape</code> at least twice?
No error
Example 8¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792c4c81c8>
2.718281828459045
SCT
test_object_accessed("arr.shape", times=2, not_accessed_msg="silly")
Result
silly
No error
Example 9¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792cefa1c8>
2.718281828459045
SCT
test_object_accessed("arr.dtype")
Result
Have you accessed <code>arr.dtype</code>?
No error
Example 10¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792c4c8288>
2.718281828459045
SCT
test_object_accessed("arr.dtype", not_accessed_msg="silly")
Result
silly
No error
Example 11¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792cefa1c8>
2.718281828459045
SCT
test_object_accessed("math.e")
Result
Great work!
No error
Example 12¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792cefa1c8>
2.718281828459045
SCT
test_object_accessed("math.pi")
Result
Have you accessed <code>m.pi</code>?
No error
Example 13¶
No PEC
Solution code
# not used
Student code
import numpy as np
import math as m
arr = np.array([1, 2, 3])
x = arr.shape
print(arr.data)
print(m.e)
Student output
<memory at 0x7f792cefaf48>
2.718281828459045
SCT
test_object_accessed("math.pi", not_accessed_msg="silly")
Result
silly
No error