KEMBAR78
Computer Science Ex | PDF | Algorithms | Computer Programming
0% found this document useful (0 votes)
13 views3 pages

Computer Science Ex

Uploaded by

sjanapriya2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views3 pages

Computer Science Ex

Uploaded by

sjanapriya2008
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

2.

USER-DEFINED FUNCTIONS

Write a menu-driven Python Program to perform sum, max, min, and sorting of numbers
using user-defined functions in list

AIM

To write a menu-driven Python Program to perform sum, max, min, sorting of number using user-
defined functions in list.

CODING

def sumlist(a):
sum=0
for i in a:
sum = sum + i
return(sum)

def maxlist(a):
max=a[0]
for i in a:
if i > max :
max = i
return(max)

def minlist(a):
min=a[0]
for i in a:
if i < min :
min = i
return(min)

def bubblesort(a):
n=len(a)
for i in range(n-1):
for j in range(n-i-1):
if a[j] > a[j+1]:
a[j],a[j+1] = a[j+1],a[j]
return(a)

a = [ ]
n = int(input("Enter the No of elements in the list : "))
for i in range(n):
print("Enter the ",i+1," Element : ",end=" ")
a.append(int(input()))
while True :
print("\n\tLIST FUNCTIONS")
print("\t~~~~~~~~~~~~~~")
print("1 - Sum of the List elements ")
print("2 - Maximum element ")
print("3 - Minimum element ")
print("4 - Sort the List ")
print("5 - Exit ")
op = int(input("Enter your Choice : "))
if op in (1,2,3,4):
print("List elements are : ", a)
if (op==1):
print("The Sum of the elements : ",sumlist(a))
elif (op==2):
print("The Maximum value is : ",maxlist(a))
elif (op==3):
print("The Minimum value is : ",minlist(a))
else:
print("The Sorted List is : ",bubblesort(a))
elif (op==5):
break
else:
print("Invalid Choice. Try again ... ")

RESULT

Thus, the above program has been executed successfully and the output is verified.

OUTPUT

Enter the No of elements in the list : 5


Enter the 1 Element : 50
Enter the 2 Element : 30
Enter the 3 Element : 10
Enter the 4 Element : 20
Enter the 5 Element : 40

LIST FUNCTIONS
~~~~~~~~~~~~~~
1 - Sum of the List elements
2 - Maximum element
3 - Minimum element
4 - Sort the List
5 - Exit
Enter your Choice : 1
List elements are : [50, 30, 10, 20, 40]
The Sum of the elements : 150
LIST FUNCTIONS
~~~~~~~~~~~~~~
1 - Sum of the List elements
2 - Maximum element
3 - Minimum element
4 - Sort the List
5 - Exit
Enter your Choice : 3
List elements are : [50, 30, 10, 20, 40]
The Minimum value is : 10

LIST FUNCTIONS
~~~~~~~~~~~~~~
1 - Sum of the List elements
2 - Maximum element
3 - Minimum element
4 - Sort the List
5 - Exit
Enter your Choice : 4
List elements are : [50, 30, 10, 20, 40]
The Sorted List is : [10, 20, 30, 40, 50]

LIST FUNCTIONS
~~~~~~~~~~~~~~
1 - Sum of the List elements
2 - Maximum element
3 - Minimum element
4 - Sort the List
5 - Exit
Enter your Choice : 5

You might also like