CodingBat: Python
codingbat.com
codingbat.com
def sum_double(a, b):
# Store the sum in a local variable
sum = a + b
# Double it if a and b are the same
if a == b:
sum = sum * 2
return sum
I wrote: def sum_double(a, b):
return (a+b)*2 if a==b else a+b
My solution was accepted. Apparently the site evaluates the python program. This is much better than some online C++ test I once took, where my entry had to match perfectly a pre-canned solution letter by letter (it would even balk on differences in whitespace).Summarised... a CS lecturer noticed that students who struggle with the small things like syntax, have less time to focus on the big issues of algorithms and data structures. The site gives short practice problems to that effect.
More challenging problems would be interesting, but there's a limit to what you can fit in the stated goal of short problems. Although, I wouldn't say that more difficult problems could be solved in similar space :)