<jupyter_start><jupyter_text>Function Practice ExercisesProblems are arranged in increasing difficulty:    Warmup - these can be solved using basic comparisons and methods    Level 1 - these may involve if/then conditional statements and simple methods    Level 2 - these may require iterating over sequences, usually with some kind of loop    Challenging - these will take some creativity to solve  WARMUP SECTION:LESSER OF TWO EVENS: Write a function that returns the lesser of two given numbers if both numbers are even, but returns the greater if one or both numbers are odd    lesser_of_two_evens(2,4) --> 2    lesser_of_two_evens(2,5) --> 5<jupyter_code># Create a function which must:
#1. Take in two values
#2. Check if the two numbers (a,b) are even or odd
#3. If even
#   compare the values & return the lesser 
#4. Else if odd
#   compare the values & return the greater

def lesserOfTwoEvens(a,b):
#if both numbers are even
    if a&2 == 0 and b%2 == 0:
        if a < b:
            result = a
        else:
            result = b
    else:
#if one or both are odd
        if a > b: 
            result = a
        else:
            result = b
    return result

lesserOfTwoEvens(43,33)
lesserOfTwoEvens(10,44)
#Refactored using the MIN, MAX functions
def lesserOfTwoEvens(a,b):
#if both numbers are even
    if a&2 == 0 and b%2 == 0:
            result = min(a,b)
    else:
#if one or both are odd
            result = max(a,b)
    return result
lesserOfTwoEvens(43,33)
lesserOfTwoEvens(10,44)<jupyter_output><empty_output><jupyter_text>ANIMAL CRACKERS: Write a function takes a two-word string and returns True if both words begin with same letter    animal_crackers('Levelheaded Llama') --> True    animal_crackers('Crazy Kangaroo') --> False<jupyter_code># Create a function which must:
#1. Take in both strings
#2. Splits or Splits and stores the first letter from each string as variable
#3. If variables from the strings match
#   Then return True
#4. Else
#   return False

#The above takes the first letter from each string

def animalCrackers(text):
    wordlist = text.split()
    
    first = wordlist[0]
    second = wordlist[1]
    
    return first [0] == second [0]
    
#Check
animalCrackers('Levelheaded Llama')
#Check
animalCrackers('Crazy Kangaroo')
#Refactored using a double index call
def animalCrackers(text):
    wordlist = text.split()
    
    return wordlist[0][0] == wordlist[1][0]
#Check
animalCrackers('Levelheaded Llama')
#Check
animalCrackers('Confused cangaroo')
#Refactoring with validation
##The below takes the string and changes the case to lower
def animaCrackers(text):
    wordlist = text.lower().split()
    print(wordlist)
    
    return wordlist[0][0] == wordlist[1][0]
#Check
animalCrackers('Levelheaded Llama')
#Check
animaCrackers('Confused Call')
%reset<jupyter_output>Once deleted, variables cannot be recovered. Proceed (y/[n])? y<jupyter_text>MAKES TWENTY: Given two integers, return True if the sum of the integers is 20 or if one of the integers is 20. If not, return False    makes_twenty(20,10) --> True    makes_twenty(12,8) --> True    makes_twenty(2,3) --> False<jupyter_code># Create a function which must:
#1. Takes in (n) integers
#2. If sum of (n) == 20 or (n[]) == 20
#    Then return True
#3. Else
#   return False

def makesTwenty(n1,n2):
    if n1 + n2 == 20:
        return True
    elif n1 == 20 :
        return True
    elif n2 == 20:
        return True
    else:
        return False
makesTwenty(20,10)
makesTwenty(12,8)
makesTwenty(2,3)
#Question - why doesn't this work if you use the word or instead of the operator? Result = no output

#def makesTwenty(n1,n2):
#    if n1 + n2 == 20:
#        return True
#    elif n1 == 20 or n2 == 20:
#        return True
#    else:
#        return False

#Question - why doesn't this work using the 'Or' operator? Result = False

def makesTwenty(n1,n2):
    if n1 + n2 == 20:  
        return True
    elif n1 == 20 | n2 == 20:
        return True
    else:
        return False
#Returns False
makesTwenty(20,10)
makesTwenty(12,8)
makesTwenty(2,3)
#Refactoring with the 'or' operator
def makesTwenty(n1,n2):
    return (n1+n2) == 20 or n1 == 20 or n2 == 20
#Returns True
makesTwenty(20,10)
makesTwenty(12,8)
makesTwenty(2,3)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09460406447091801, 'fraction_numerical': 0.03433777154870357, 'mean_word_length': 3.3035175879396985, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '383406', 'license': 'MIT', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1388, 'n_words': 522, 'path': '[Self Help] Python/Notes - Learning Resources/Functions & Methods/[Section 6] Function Practice Exercises {Code Along}.ipynb', 'repo_name': 'amuganda/MacOS_Repository_Restructured', 'size': '4281'}