google.com, pub-8786015629279405, DIRECT, f08c47fec0942fa0 Write a Program to Find the largest of n numbers, using a user defined function largest()

Write a Program to Find the largest of n numbers, using a user defined function largest()

0

 



# Write a Program to Find the largest of n numbers,
# using a user defined function largest()

# First we declare a Function
# name should be largest()

def largest(list1):  # its take a list
   
top = list1[0]
   
for a in list1:
       
if a > top:
            top = a
   
return top


# Call the Function
# take a blank list
li = []

# input the size of list

num = int(input("How Many Elements in the List"))
for i in range(num):
    number =
int(input("Enter the Element "))
    li.append(number)
   
# Print the Largest Value

print("Largest Element in the List is:", largest(li))

Output:

How Many Elements
in the List3
Enter the Element
56
Enter the Element 12
Enter the Element -47
Largest Element in the List is: 56

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Thank you for your interest 😊

We will back shortly after reviewing...

Thank you for your interest 😊

We will back shortly after reviewing...

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Accept !
To Top