forked from tdwojak/Python2017
resolve2
This commit is contained in:
parent
f841b1e161
commit
66223f51c8
@ -1,3 +1,34 @@
|
||||
#!/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))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user