Learn Programming and technology with ease @ developerpublish.com

HomePythonPython Program to Find Largest Number in a List

# Python Program to Find Largest Number in a List

In this Python program, weâ€™ll create a script to find the largest number in a given list of numbers.

## Problem Statement:

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[0]
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

## Input:

Enter a list of numbers separated by spaces: 10 25 5 48 32

## Output

The largest number in the list is: 48

### You May Also Like

#### Python Program to Remove Duplicates from a Linked List

In this Python program, we will create a singly linked list and remove duplicate elements from it. A linked list...

#### Python Program to Solve the Celebrity Problem

This Python program solves the Celebrity Problem by finding a person who is known by everyone but does not know...

#### Python Program to Solve n-Queen Problem with Recursion

This Python program uses a recursive approach to solve the n-Queens problem. It explores all possible combinations of queen placements...