Tags | technical-assessment skill/return_and_print |
Students should 100% understand the following concepts. Note that simply memorizing this stuff will be insufficient. In the final test, the different concepts will be combined in complex ways.
Make use of print statements to check that the student knows what order things will happen in.
On Tilde you will notice that this card is asking for a link submission. Please don’t worry about submitting a link. You will be assessed according to TOPIC: Introduction to live assessments
A lot of people get this wrong because they learn to code using a REPL. Java folks are less likely to fall into this trap.
Here are some basic code examples. It is in Python but easy to translate to other languages.
def foo():
print("hi")
x = foo()
print(f"x = {x}")
Many think that the code will print x = hi
. It does not.
For example:
def foo(colour):
if colour == "blue":
return 1
return 2
x = foo("blue")
x = foo("red")
print(f"x = {x}")
Many people think that the final print statement gets executed multiple times but it does not.
def foo():
for i in range(10):
return i
x = foo()
print(f"x = {x}")
def foo(*args):
return args
x = foo()
print(f"x = {x}")
Many people think that the above will print x = None
. It will not.
foo();
function foo() {
console.log("hello");
}
Many people assume that the code above will raise an error. It does not.