Write a Python program to find the maximum and minimum number in a lis...
# Python program to find the maximum and minimum number in a list of number/ tuple
# entering a list of number from user
list1=eval(input (" enter or list of number"))
length=len (list1)
# finding the maximum number and minimum number in the list
for i in range(0, length) :
maximum=max(list1)
minimum=min(list1)
# displaying maximum and minimum number
print (" the maximum number in the list is:", maximum)
print(" the minimum number in the list is:", minimum)
Write a Python program to find the maximum and minimum number in a lis...
Introduction:
Python is a popular programming language widely used in various domains, including data science, web development, machine learning, and artificial intelligence. In this article, we will explore how to find the maximum and minimum number in a list of numbers/tuple using Python.
Steps to find the maximum and minimum number:
To find the maximum and minimum number in a list of numbers/tuple using Python, follow the steps below:
1. Create a list/tuple of numbers.
2. Initialize two variables, one for storing the maximum number and the other for storing the minimum number.
3. Iterate over the list/tuple using a loop.
4. Compare each number in the list/tuple with the maximum and minimum number variables.
5. Update the maximum and minimum number variables accordingly.
6. Print the maximum and minimum number.
Python code to find the maximum and minimum number:
Here is the Python code to find the maximum and minimum number in a list/tuple:
```
# create a list/tuple of numbers
numbers = [1, 2, 3, 4, 5]
# initialize maximum and minimum number variables
max_number = numbers[0]
min_number = numbers[0]
# iterate over the list/tuple
for number in numbers:
# compare each number with the maximum number variable
if number > max_number:
max_number = number
# compare each number with the minimum number variable
if number < />
min_number = number
# print the maximum and minimum number
print("Maximum number:", max_number)
print("Minimum number:", min_number)
```
Conclusion:
In this article, we have learned how to find the maximum and minimum number in a list/tuple using Python. We have explained the steps involved in finding the maximum and minimum number and provided Python code for the same.
To make sure you are not studying endlessly, EduRev has designed Class 10 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 10.