Function to Find Maximum Value in an Array - Python Programming Exercise

In this exercise, you will develop a Python program containing a function that accepts a list of floating-point numbers as input and returns the maximum value within the list. This exercise is perfect for practicing function definition, list manipulation, and comparison operations in Python. By implementing this function, you will gain hands-on experience in handling function definitions, list manipulation, and comparison operations in Python. This exercise not only reinforces your understanding of functions but also helps you develop efficient coding practices for managing user interactions.

 Category

Mastering Functions

 Exercise

Function To Find Maximum Value In An Array

 Objective

Develop a Python program containing a function that accepts a list of floating-point numbers as input and returns the maximum value within the list: data = [1.5, 0.7, 8.0] max_value = maximum(data)

 Example Python Exercise

 Copy Python Code
# Function to find the maximum value in a list of floating-point numbers
def maximum(data):
    # Return the maximum value from the list
    return max(data)

# Main function to demonstrate the maximum function
def main():
    # Input list of floating-point numbers
    data = [1.5, 0.7, 8.0]
    
    # Call the maximum function and store the result
    max_value = maximum(data)
    
    # Print the result
    print(f"The maximum value in the list is {max_value}")

# Run the main function
if __name__ == "__main__":
    main()

 Output

The maximum value in the list is 8.0

 Share this Python Exercise

 More Python Programming Exercises of Mastering Functions

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Iterative Implementation of the Factorial Function

    In this exercise, you will develop a Python program that calculates the factorial of a given number using an iterative (non-recursive) method. This exercise is...

  •  Function to Print Title

    In this exercise, you will develop a Python program with a function called 'WriteTitle' that displays a text in uppercase, centered on the screen with extra spaces an...

  •  Main Function Output Value

    In this exercise, you will develop a Python program that prompts the user to provide a title via the command line (using the previously defined WriteTitle function). ...

  •  Function to Calculate DV

    In this exercise, you will develop a Python program that defines a function to count the number of numeric digits and vowels in a given string. The function should ta...

  •  Function to Verify Alphabetic Characters

    In this exercise, you will develop a Python program that includes a function to determine if a given character is alphabetic (from A to Z). This exercise is pe...

  •  Function to Check Numeric Value

    In this exercise, you will develop a Python program that defines a function to check if a string represents an integer value. This exercise is perfect for prac...