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 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz