Software Development Exam  >  Software Development Notes  >  Basics of Python  >  Functions: Practice Problems

Functions: Practice Problems | Basics of Python - Software Development PDF Download

Problem 1: Write a Python function called max_of_three to find the maximum value between three numbers. Do not use the max() function.

Hint: in my solution, I found it easiest to create a different function called max_of_two and use that function to base my max_of_three off of.

def max_of_two( x, y ):

    if x > y:

        return x

    return y

def max_of_three( x, y, z ):

    return max_of_two( x, max_of_two( y, z ) )

print(max_of_three(3, 6, -5))

Problem 2: Write a Python function called multiply to multiply all of the numbers in a list together and return that value. The function should be created in such a way that it will work for both lists, tuples, and sets.

def multiply(numbers):  

    total = 1

    for x in numbers:

        total *= x  

    return total  

testList = [8, 2, 3, -1, 7]


Problem 3: Write a Python function called caseCounter that counts the number of lowercase and uppercase characters in a string. If you're up to it, store the lowercase and uppercase variables in a dictionary within the function. The function should print two sentences that state the number of uppercase and lowercase characters.

def caseCounter(s):

    d={"UPPER_CASE":0, "LOWER_CASE":0}

    for c in s:

        if c.isupper():


        elif c.islower():




    print ("No. of uppercase characters : ", d["UPPER_CASE"])

    print ("No. of lowercase Characters : ", d["LOWER_CASE"])

    print(caseCounter('Nicholas McCullum'))

Problem 4: Write a Python function called duplicateEliminator that takes in a list, eliminates any duplicate values, and returns a set.
Hint: This is probably easier than you think.

def duplicateEliminator(l):

    return set(l)


Problem 5: Write a Python function called squareMachine that takes in a list and returns another list whose elements are the values of the first list squared.

def squareMachine(theList):

    i = 0

    while i < len(theList):

        theList[i] = theList[i]**2

        i += 1

    return theList


Problem 6: Write a Python function called dictDecomposer that takes in a dictionary and prints two lines of text:

  • One line stating the keys of the dictionary
  • One line stating the values of the dictionary

An example output from the correct solution is below:
The keys of the dictionary are ['firstName', 'lastName']
The values of the dictionary are ['Nick', 'McCullum']

def dictDecomposer(theDict):

    print(f"The keys of the dictionary are {list(theDict.keys())}")

    print(f"The values of the dictionary are {list(theDict.values())}")

    testDictionary = {

    'firstName': 'Nick',

    'lastName': 'McCullum'



The document Functions: Practice Problems | Basics of Python - Software Development is a part of the Software Development Course Basics of Python.
All you need of Software Development at this link: Software Development
49 videos|38 docs|18 tests
49 videos|38 docs|18 tests
Download as PDF
Explore Courses for Software Development exam
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Download the FREE EduRev App
Track your progress, build streaks, highlight & save important lessons and more!
Related Searches

Functions: Practice Problems | Basics of Python - Software Development


Functions: Practice Problems | Basics of Python - Software Development


Important questions




shortcuts and tricks


Objective type Questions




Sample Paper




Semester Notes








study material


Viva Questions


video lectures


Extra Questions


mock tests for examination


Previous Year Questions with Solutions


Functions: Practice Problems | Basics of Python - Software Development


practice quizzes


past year papers