Python: Check whether a specified value is contained in a group of values
Python Basic: Exercise-25 with Solution
Write a Python program to check whether a specified value is contained in a group of values.
Test Data:
3 -> [1, 5, 8, 3] : True
-1 -> [1, 5, 8, 3] : False
3 -> [1, 5, 8, 3] : True
-1 -> [1, 5, 8, 3] : False
Sample Solution:-
def is_group_member(group_data, n):
for value in group_data:
if n == value:
return True
return False
print(is_group_member([1, 5, 8, 3], 3))
print(is_group_member([5, 8, 3], -1))
=========== RESTART: F:/Python_APSC/py-ex-basic-25.py ========
True
False
>>>
沒有留言:
張貼留言