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

Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad