How to find the greatest number in a list in Python

0 votes
Is there any easy way or a builtin function to determine the greatest number in a python list? Can we find it without using builtin functions?
Aug 21, 2019 in Python by Arvind
• 3,050 points
3,351 views

1 answer to this question.

0 votes

1. By using max function - 

highest = max(11, 21, 31) 
print(highest) # prints 31

2. Without using max function

a=[11,22,33,44,66,77,99,88,999]
max= 0
for i in a:
    if i > max:
        max=i
print(max) # prints 999
answered Aug 21, 2019 by Neel
• 3,020 points
What if we write max=i directly down the line if i> max
0 votes

Consider a list of numbers. Write a Python program to do the following:

1) Count total number of numbers in the list  

2) Sum and Average of all the numbers in the list  

3) Count and sum of all the odd numbers in the list  

4) Count and sum of all the even numbers in the list  

5) Find the largest number in the list  

6) Find the smallest number in the list  

Display all the values with appropriate titles.  

listNo = [6,8,10,44,33,21,7,1,0,2]

c = 0

s = 0

avg = 0

sOdd = 0

sEven = 0

cOdd = 0

cEven = 0

for i in listNo :

    c += 1

    s = s+i

    avg = s/c

    if i % 2 == 0 :

        sEven = sEven + i

        cEven = cEven + 1

    else :

        sOdd = sOdd + i

        cOdd = cOdd + 1

print ("total number of numbers in the list  : ", c)

print("sum of all numbers : ",s)

print("average of all numbers : ",avg)

print("count odd numbers : ",cOdd)

print("sum of odd numbers : ",sOdd)

print("count even numbers : ",cEven)

print("sum of odd numbers : ",sEven)

print("largest number in the list : " ,max(listNo))

print("smallest number in the list  : ",min(listNo))

answered Apr 14, 2021 by anonymous

edited Mar 5

Related Questions In Python

–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,270 points
3,159 views
+1 vote
1 answer
0 votes
1 answer

How can I find the square of a number in python?

You can use the exponentiation operator or ...READ MORE

answered May 21, 2019 in Python by Mohammad
• 3,230 points