1.find the largest of n numbers, using user define function largest () in python
Answers
Answer:
def largest(nums):
nums_sorted = nums.sort()
largest_number = nums_sorted[-1]
return largest_number
or
def largest(nums):
return (nums.sort())[-1]
Explanation:
nums must be a list that is all
sort sorts ascending order
-1 gets last number
Answer:
Python program to find the largest of n numbers, using user define function largest ()
Explanation:
From the above question,
They have given :
The largest of n numbers, using user define function largest () in python.
def largest(list):
largest = list[0]
for i in list:
if i>largest:
largest = i
return largest
list = [1,2,3,4,5]
print("Largest element is:", largest(list))
This function takes a list of numbers as an argument and finds the largest number in the list. It first sets the largest number to the first element in the list, and then iterates through the list comparing each number to the largest number. If a number is larger than the current largest number, it is set to the largest number. Finally, the largest number is returned.
For more such related questions : https://brainly.in/question/54845385
#SPJ3