2018年1月8日 星期一

Python: Check whether a specified value is contained in a group of values

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
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
>>> 

沒有留言:

張貼留言

8-QAM Signal 4 Phases 2 Amplitudes + 8PSK

 8-QAM Signal 4 Phases 2 Amplitudes + 8PSK import tkinter as tk from tkinter import messagebox import math import cmath # --- 8-QAM 參數設定 ---...