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