def swap(x, y): @ @f1@@ if 'x' not in locals(): raise pythia.UndeclaredException('x') if 'y' not in locals(): raise pythia.UndeclaredException('y') if type(x) != int: raise pythia.BadTypeException('x', type(x), int) if type(y) != int: raise pythia.BadTypeException('y', type(y), int) return (x, y)
def toursnumber(A, B): @ @f1@@ if 'pierre' not in locals(): raise pythia.UndeclaredException('pierre') if 'claire' not in locals(): raise pythia.UndeclaredException('claire') if type(pierre) != int: raise pythia.BadTypeException('pierre', type(pierre), int) if type(claire) != int: raise pythia.BadTypeException('claire', type(claire), int) return (pierre, claire)
def simplify(time): @ @f1@@ if 'minutes' not in locals(): raise pythia.UndeclaredException('minutes') if 'seconds' not in locals(): raise pythia.UndeclaredException('seconds') if type(minutes) != int: raise pythia.BadTypeException('minutes', type(minutes), int) if type(seconds) != int: raise pythia.BadTypeException('seconds', type(seconds), int) return (minutes, seconds)
def intanddec(s): @ @f1@@ if 'i' not in locals(): raise pythia.UndeclaredException('i') if 'd' not in locals(): raise pythia.UndeclaredException('d') if type(i) != int: raise pythia.BadTypeException('i', type(i), int) if type(d) != float: raise pythia.BadTypeException('d', type(d), float) return (i, d)
def computeend(hour, minute, second, duration): @ @f1@@ if 'endhour' not in locals(): raise pythia.UndeclaredException('endhour') if 'endminute' not in locals(): raise pythia.UndeclaredException('endminute') if type(endhour) != int: raise pythia.BadTypeException('endhour', type(endhour), int) if type(endminute) != int: raise pythia.BadTypeException('endminute', type(endminute), int) return (endhour, endminute)
def checktemp(temperature, thermostat): @ @f1@@ if 'outlimits' not in locals(): raise pythia.UndeclaredException('outlimits') if 'thermostat' not in locals(): raise pythia.UndeclaredException('thermostat') if type(outlimits) != bool: raise pythia.BadTypeException('outlimits', type(outlimits), bool) if type(thermostat) != int: raise pythia.BadTypeException('thermostat', type(thermostat), int) return (outlimits, thermostat)
def isbool(x): @ @f1@@ if 'ok' not in locals(): raise pythia.UndeclaredException('ok') if type(ok) != bool: raise pythia.BadTypeException('ok', type(ok), bool) return ok
def taxincluded(price, rate): @ @f1@@ if 'fullprice' not in locals(): raise pythia.UndeclaredException('fullprice') if type(fullprice) != float: raise pythia.BadTypeException('fullprice', type(fullprice), float) return fullprice
def sumsinus(a, b): @ @f1@@ if 'result' not in locals(): raise pythia.UndeclaredException('result') if type(result) != float: raise pythia.BadTypeException('result', type(result), float) return result
def canbuy(unitprice, quantity, money): @ @f1@@ if 'buy' not in locals(): raise pythia.UndeclaredException('buy') if type(buy) != bool: raise pythia.BadTypeException('buy', type(buy), bool) return buy
def theaterprice(age, loyalty): @ @f1@@ if 'price' not in locals(): raise pythia.UndeclaredException('price') if type(price) != int: raise pythia.BadTypeException('price', type(price), int) return price
def syracuse(n): @ @f1@@ if 'time' not in locals(): raise pythia.UndeclaredException('time') if type(time) != int: raise pythia.BadTypeException('time', type(time), int) return time
def convert(temperature, unit, to): @ @f1@@ if 'result' not in locals(): raise pythia.UndeclaredException('result') if type(result) != float: raise pythia.BadTypeException('result', type(result), float) return result
def isforbidden(height): @ @f1@@ if 'forbidden' not in locals(): raise pythia.UndeclaredException('forbidden') if type(forbidden) != bool: raise pythia.BadTypeException('forbidden', type(forbidden), bool) return forbidden
def binom(n, k): @ @f1@@ if 'coeff' not in locals(): raise pythia.UndeclaredException('coeff') if type(coeff) != int: raise pythia.BadTypeException('coeff', type(coeff), int) return coeff
def computesum(n): @ @f1@@ if 'result' not in locals(): raise pythia.UndeclaredException('result') if type(result) != int: raise pythia.BadTypeException('result', type(result), int) return result
def computeprice(quantity, unitprice, loyalty): @ @f1@@ if 'totalprice' not in locals(): raise pythia.UndeclaredException('totalprice') if type(totalprice) != float: raise pythia.BadTypeException('totalprice', type(totalprice), float) return totalprice
def printdate(day, month, year): @ @f1@@ if 'date' not in locals(): raise pythia.UndeclaredException('date') if type(date) != str: raise pythia.BadTypeException('date', type(date), str) return date
def getvalue(): @ @f1@@ if not 'x' in locals(): raise pythia.UndeclaredException('undeclared') elif not type(x) == int: raise pythia.BadTypeException('badtype') return x
def lettersinterval(start, end): @ @f1@@ if 'result' not in locals(): raise pythia.UndeclaredException('result') if type(result) != str: raise pythia.BadTypeException('result', type(result), str) return result
def containstype(x): @ @f1@@ if 'istype' not in locals(): raise pythia.UndeclaredException('istype') if type(istype) != bool: raise pythia.BadTypeException('istype', type(istype), bool) return istype
def absval(x): @ @f1@@ if 'x' not in locals(): raise pythia.UndeclaredException('x') if type(x) != int: raise pythia.BadTypeException('x', type(x), int) return x
def isprime(n): @ @f1@@ if 'prime' not in locals(): raise pythia.UndeclaredException('prime') if type(prime) != bool: raise pythia.BadTypeException('prime', type(prime), bool) return prime
def concat(hour, minute, second): @ @f1@@ if 'result' not in locals(): raise pythia.UndeclaredException('result') if type(result) != str: raise pythia.BadTypeException('result', type(result), str) return result
def studentCode(self, data): find = [f for (n, f) in inspect.getmembers(q1, inspect.isfunction) if n == 'isperfect'] if len(find) != 1: raise pythia.UndeclaredException('isperfect') if not callable(find[0]): raise pythia.BadTypeException('isperfect', type(find[0]), 'function') spec = inspect.getargspec(find[0]) if len(spec.args) != 1: raise pythia.WrongParameterNumberException('isperfect', len(spec.args), 1) return q1.isperfect(data)
sys.stdout = open('/tmp/work/output/stdout', 'w') sys.stderr = open('/tmp/work/output/stderr', 'w') # Try to import student's code sys.path.append('/tmp/work') try: import q1 except Exception as e: print(e, file=sys.stderr) sys.exit(0) # Execute student's code try: find = [f for (n, f) in inspect.getmembers(q1, inspect.isfunction) if n == 'printhelloworld'] if len(find) != 1: raise pythia.UndeclaredException('printhelloworld') if not callable(find[0]): raise pythia.BadTypeException('printhelloworld', type(find[0]), 'function') spec = inspect.getargspec(find[0]) if len(spec.args) != 0: raise pythia.WrongParameterNumberException('printhelloworld', len(spec.args), 0) q1.printhelloworld() except pythia.UndeclaredException as e: print('exception:undeclared:{}'.format(e.name), file=sys.stderr) except pythia.BadTypeException as e: print('exception:badtype:{}:{}:{}'.format(e.name, e.actualtype, e.expectedtype), file=sys.stderr) except pythia.WrongParameterNumberException as e: print('exception:wrongparameterexception:{}:{}:{}'.format(e.name, e.actualnumber, e.expectednumber), file=sys.stderr) except Exception as e: print('exception:{}'.format(e), file=sys.stderr)
def truthvalue(a, b, c): result = @@f1@@ if type(result) != bool: raise pythia.BadTypeException('result', type(result), bool) return result
# -*- coding: utf-8 -*- # Course: Apprendre Python # Problem: Variable modification import sys sys.path.append('/task/static') from lib import pythia def getvalue(): x = 10 @ @f1@@ if not 'x' in locals(): raise pythia.UndeclaredException('deleted') elif not type(x) == int: raise pythia.BadTypeException('badtype') return x
def div2and3(n): S = @@f1@@ if type(S) != set: raise pythia.BadTypeException('S', type(S), set) return S
def absval(x): result = @@f1@@ if type(result) != int: raise pythia.BadTypeException('result', type(result), int) return result