mode: null-fields

split: train

spec: solve(order) → order['qty'] as int, default 1 if missing or None.

hidden_test:
from solution import solve
assert solve({'qty':3})==3
assert solve({})==1
assert solve({'qty':None})==1

reference_broken:
def solve(o):
    return int(o['qty'])

reference_fixed:
def solve(o):
    v=o.get('qty')
    return 1 if v is None else int(v)


split: holdout

spec: solve(user) → user['name'] stripped, default 'guest' if missing/None/blank.

hidden_test:
from solution import solve
assert solve({'name':' Al '})=='Al'
assert solve({})=='guest'
assert solve({'name':None})=='guest'
assert solve({'name':'  '})=='guest'

reference_broken:
def solve(u):
    return u['name'].strip()

reference_fixed:
def solve(u):
    v=u.get('name')
    v=(v or '').strip()
    return v if v else 'guest'


spec: solve(item) → float(item['price']), default 0.0 if missing or None.

hidden_test:
from solution import solve
assert solve({'price':'2.5'})==2.5
assert solve({})==0.0
assert solve({'price':None})==0.0

reference_broken:
def solve(i):
    return float(i['price'])

reference_fixed:
def solve(i):
    v=i.get('price')
    return 0.0 if v is None else float(v)


spec: solve(post) → number of tags in post['tags'], default 0 if key missing or None.

hidden_test:
from solution import solve
assert solve({'tags':['a','b']})==2
assert solve({})==0
assert solve({'tags':None})==0

reference_broken:
def solve(p):
    return len(p['tags'])

reference_fixed:
def solve(p):
    v=p.get('tags')
    return 0 if v is None else len(v)


mode: type-coercion

spec: solve(rows) → numeric sum of a list of string integers like '12','8'.

hidden_test:
from solution import solve
assert solve(['12','8'])==20
assert solve([])==0
assert solve(['3','3','4'])==10

reference_broken:
def solve(r):
    return sum(r)

reference_fixed:
def solve(r):
    return sum(int(x) for x in r)


spec: solve(vals) → the largest value in a list of numeric strings, as int.

hidden_test:
from solution import solve
assert solve(['2','10','7'])==10
assert solve(['5'])==5

reference_broken:
def solve(v):
    return int(max(v))

reference_fixed:
def solve(v):
    return max(int(x) for x in v)


spec: solve(scores) → integer average (floor) of a list of numeric strings.

hidden_test:
from solution import solve
assert solve(['10','20'])==15
assert solve(['3','3','4'])==3

reference_broken:
def solve(s):
    return sum(s)//len(s)

reference_fixed:
def solve(s):
    n=[int(x) for x in s]
    return sum(n)//len(n)


mode: edge-empty

spec: solve(nums) → sum of a list of ints; 0 for empty.

hidden_test:
from solution import solve
assert solve([1,2,3])==6
assert solve([])==0
assert solve([-2,2])==0

reference_broken:
def solve(n):
    return n[0]+sum(n[1:])

reference_fixed:
def solve(n):
    return sum(n)


spec: solve(xs) → first element, or None if empty.

hidden_test:
from solution import solve
assert solve([9,8])==9
assert solve([])is None

reference_broken:
def solve(x):
    return x[0]

reference_fixed:
def solve(x):
    return x[0] if x else None


spec: solve(nums) → average as float, or 0.0 for empty list.

hidden_test:
from solution import solve
assert solve([2,4])==3.0
assert solve([])==0.0

reference_broken:
def solve(n):
    return sum(n)/len(n)

reference_fixed:
def solve(n):
    return sum(n)/len(n) if n else 0.0


mode: off-by-one

spec: solve(items) → last element, or None if empty.

hidden_test:
from solution import solve
assert solve([1,2,3])==3
assert solve([])is None
assert solve(['a'])=='a'

reference_broken:
def solve(i):
    return i[len(i)-2] if i else None

reference_fixed:
def solve(i):
    return i[-1] if i else None


spec: solve(xs, n) → the last n elements in order.

hidden_test:
from solution import solve
assert solve([1,2,3,4],2)==[3,4]
assert solve([1],3)==[1]

reference_broken:
def solve(x,n):
    return x[len(x)-n+1:]

reference_fixed:
def solve(x,n):
    return x[-n:] if n<=len(x) else x[:]


mode: precision

spec: solve(cents) → dollars string like '1.05' from an integer number of cents.

hidden_test:
from solution import solve
assert solve(105)=='1.05'
assert solve(100)=='1.00'
assert solve(9)=='0.09'

reference_broken:
def solve(c):
    return str(c/100)


spec: solve(part, whole) → percentage rounded to 1 decimal, as a string like '33.3'.

hidden_test:
from solution import solve
assert solve(1,3)=='33.3'
assert solve(1,2)=='50.0'

reference_broken:
def solve(p,w):
    return str(p/w*100)

reference_fixed:
def solve(p,w):
    return f'{round(p/w*100,1):.1f}'


mode: ordering

spec: solve(xs) → duplicates removed, first-seen order preserved; empty→empty.

hidden_test:
from solution import solve
assert solve([1,1,2,3,2])==[1,2,3]
assert solve([])==[]
assert solve(['a','a'])==['a']

reference_broken:
def solve(x):
    return list(set(x))

reference_fixed:
def solve(x):
    s=[]
    for v in x:
        if v not in s: s.append(v)
    return s


spec: solve(n) → n doubled.

hidden_test:
from solution import solve
assert solve(4)==8
assert solve(0)==0
assert solve(-3)==-6

reference_broken:
def solve(n):
    return n*2

reference_fixed:
def solve(n):
    return n*2


spec: solve(s) → s uppercased.

hidden_test:
from solution import solve
assert solve('hi')=='HI'
assert solve('')==''

reference_broken:
def solve(s):
    return s.upper()

reference_fixed:
def solve(s):
    return s.upper()