Cyrus Cueva Baruc


Business Analyst/Power BI Developer

Hometown: Bantayan Island
Current City: Lapu-Lapu City
Phone: +639565028805
Email: cirobar@outlook.com
LinkedIn: Cyrus Baruc
My CV: Click To Download

Exercises on Functions

Implement the following functions:

doubledInt()

# your code here

def doubledInt(x):
    return x * 2

doubledInt(10)
20

fullName()

# your code here

def fullName(lastname,firstname, middlename = ""):
    try:
        return f"{firstname} {middlename[0]}. {lastname}"
    except IndexError:
       return f"{firstname} {lastname}"
        
fullName("Baruc","Cyrus","C")
'Cyrus C. Baruc'

largest()

# your code here

def largest(x,y):
    return max(x,y)

largest(19,91)
    
91

isVerticalLine()

# your code here

def isVerticalLine(point1, point2):
    x1,y1 = point1
    x2,y2 = point2
    return x1 == x2 and y1 != y2

isVerticalLine((0,4),(0,5))

True
# your code here

def head(list, n = 0):
    if len(list) == 0:
        return list
    elif int == 0:
        return list[0]
    else:
        return list[:n]

x = [2,4,6,8,10,12,14,16,18,20]
        
head(x,5)
[2, 4, 6, 8, 10]

dictionary()

# your code here
def dictionary(list1, list2):
    if len(list1) != len(list2):
        return None
    else:
        return dict(zip(list1,list2))

x = ["Month","Date","Year"]
y = [7,11,2024]

dictionary(x,y)
    
{'Month': 7, 'Date': 11, 'Year': 2024}

mean()

# your code here
def mean(x):
    return sum(x)/len(x)

x = [5,10,15,20,25,30]
mean(x)
17.5

variance()

# your code here
def variance(list):
    mean = sum(list)/len(list)
    sq_dif = [(x-mean) ** 2 for x in list]
    total_sq_dif = sum(sq_dif)
    var = total_sq_dif / len(list)
    return var

nums =[5,10,15,20,21,22,30]

variance(nums)
        
    
59.10204081632653

filterValues()

# your code here
def filterValues(numbers, min_value=None, max_value=None):
    if min_value is None:
        min_value = 0
    if max_value is None:
        max_value = 100

    filtered_numbers = [num for num in numbers if min_value <= num <= max_value]
    return filtered_numbers
numbers = [10, -5, 120, 50, 200, 75, -10, 30, 0, 99, 101]

print(filterValues(numbers, max_value = 80))


[10, 50, 75, 30, 0]