Programming Examples

Python function which takes list of integers as input and finds the followings


Write a Python function which takes list of integers as input and finds:

(a) The largest positive number in the list

(b) The smallest negative number in the list

(c) Sum of all positive numbers in the list

Solution

def calculate(*arg):
    print("Largest Number : ",max(arg))
    print("Smallest Number : ",min(arg))
    s=0
    for a in arg:
        if a>0:
            s=s+a
    print("Sum of all Positive Number : ",s)
calculate(1,-2,4,3)
Output

Largest Number :  4

Smallest Number :  -2

Sum of all Positive Number :  8

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad