MODULE – 4 ASSIGNMENT
Functions
Please write Python Programs for all the problems.
1. Python function to find the maximum of three numbers
def max_of_three(a, b, c):
if a >= b and a >= c:
return a
elif b >= a and b >= c:
return b
else:
return c
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
num3 = int(input("Enter third number: "))
print("The maximum number is:", max_of_three(num1, num2, num3))
2. Python function to sum all the numbers in a list
def sum_of_list(numbers):
total = 0
for num in numbers:
total += num
return total
© 360DigiTMG. All Rights Reserved.
num_list = list(map(int, input("Enter numbers: ").split()))
print("The sum of all numbers in the list is:", sum_of_list(num_list))
3. Python function to multiply all the numbers in a list
def multiply_list(numbers):
result = 1
for num in numbers:
result *= num
return result
num_list = list(map(int, input("Enter numbers: ").split()))
print("The product of all numbers in the list is:", multiply_list(num_list))
© 360DigiTMG. All Rights Reserved.