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/ Explanation:

Largest Number :  4

Smallest Number :  -2

Sum of all Positive Number :  8

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad