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
2,965 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
2,416 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
1,359 views
0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
19,473 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,645 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,419 views
0 votes
1 answer

How to get permutations of list or a set in Python?

Permutation is an arrangement of objects in ...READ MORE

answered Jul 11, 2019 in Python by Neel
• 3,020 points
9,074 views
0 votes
1 answer

How to add elements to a list in Python?

To initialize an empty list do this: new_list ...READ MORE

answered Jul 23, 2019 in Python by Neel
• 3,020 points
946 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP