forked from tdwojak/Python2017
35 lines
902 B
Python
35 lines
902 B
Python
#!/usr/bin/env python2
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
**ćwiczenie 1**
|
|
Napisz funckję ``is_numeric``, która sprawdzi, czy każdy element z przekazanej listy jest typu int lub float.
|
|
Wykorzystaj funcję ``isinstance()`` (https://docs.python.org/2/library/functions.html#isinstance).
|
|
"""
|
|
|
|
|
|
def is_numeric(n):
|
|
if isinstance(n,int):
|
|
return 'type int'
|
|
elif isinstance(n,float):
|
|
return 'type float'
|
|
elif isinstance(n,str):
|
|
return 'type string'
|
|
else:
|
|
return 'type unavailable'
|
|
|
|
|
|
def tests(f):
|
|
inputs = [1,2,5,'test',2,4.32423]
|
|
outputs = ['type int','type int','type int','type string','type int','type float']
|
|
|
|
for input, output in zip(inputs, outputs):
|
|
if f(input) != (output):
|
|
return "ERROR: {}!={}".format(f(input), output)
|
|
break
|
|
return "TESTS PASSED"
|
|
|
|
if __name__ == "__main__":
|
|
print(tests(is_numeric))
|
|
|