Python Function Calling

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:
  1. isinstance(“abc”, str)
  2. isinstance([1, 2, 3], list)

or

  1. type(“abc”) == str
  2. type([1, 2, 3]) == lst
It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *