1
0
forked from tdwojak/Python2017
Python2017/labs04/task01.py

32 lines
874 B
Python
Raw Normal View History

2017-12-03 13:05:05 +01:00
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
2017-12-03 15:09:31 +01:00
# **ć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(another_list):
2017-12-13 10:31:24 +01:00
"""
Check whether each element of the list is an instance of int or float
:param another_list:
:return: True or False
"""
2017-12-03 15:09:31 +01:00
for i in another_list:
2017-12-13 10:31:24 +01:00
if isinstance(i, bool):
return False
elif isinstance(i, (int, float)):
i += 1
2017-12-03 15:09:31 +01:00
else:
2017-12-13 10:31:24 +01:00
return False
return True
2017-12-03 15:09:31 +01:00
2017-12-13 10:31:24 +01:00
# 2nd option
2017-12-03 15:09:31 +01:00
2017-12-13 10:31:24 +01:00
# if type(i) in (float, int):
# i += 1
# else:
# return False
# return True
2017-12-03 15:09:31 +01:00
2017-12-13 10:31:24 +01:00
# print(is_numeric([2, 1.8797, 43654354354354354354354354354354354325879]))