def mean(value): if type(value)==dict: the_mean=sum(value.values())/len(value.values()) else: the_mean = sum(value) / len(value) return the_mean monday_temperatures=(8.8,9.1,9.9) student_grades={"Marry":9.1,"sim":8.8,"John":7.5} print(mean(monday_temperatures))
def mean(value): if isinstance(value,dict): the_mean=sum(value.values())/len(value.values()) else: the_mean = sum(value) / len(value) return the_mean monday_temperatures=(8.8,9.1,9.9) student_grades={"Marry":9.1,"sim":8.8,"John":7.5} print(mean(monday_temperatures))
def foo(x, array): if x in array: return True else: return False print(foo("z", ["a", "b", "z"])) print(foo(1, [2, 3])) print(foo(1, ['1', 2, 3]))
def inTake(value): length = len(value) if length < 8: return False else: return True print(inTake("mylongspass"))
def inTake(value): if value > 25 : return "hot" elif value>=15 and value<=25: return "warm" else: return "Cold" print(inTake(20))
def inTake(value): if value > 25 : return "hot" elif value>=15 and value<=25: return "warm" else: return "Cold" inputdigit=float(input("enter temperature=")) print(inTake(inputdigit)) print(type(inputdigit),inputdigit)
- Check if a value is of a certain type with:
- isinstance(“abc”, str)
- isinstance([1, 2, 3], list)
or
- type(“abc”) == str
- type([1, 2, 3]) == lst