In this Python program, we’ll create a script to find the largest number in a given list of numbers.
You are required to write a program in python that takes a list of numbers as input and finds the largest number among them.
Python Program to Find Largest Number in a List
def find_largest_number(numbers): if not numbers: return None largest = numbers for num in numbers: if num > largest: largest = num return largest # Input: List of numbers numbers = [int(x) for x in input("Enter a list of numbers separated by spaces: ").split()] # Call the function and print the result result = find_largest_number(numbers) print("The largest number in the list is:", result)
How it Works:
The program defines a function find_largest_number that takes a list of numbers as an argument.It initializes the largest variable with the first number in the list.It iterates through the list, comparing each number with the current largest. If a number is greater than the current largest, the largest variable is updated.After iterating through all numbers, the program returns the largest number.The user is prompted to input a list of numbers, which are converted to integers and stored in the numbers list.The find_largest_number function is called with the numbers list as an argument, and the result is printed
Enter a list of numbers separated by spaces: 10 25 5 48 32
The largest number in the list is: 48