Python Program to Find Largest of N Numbers using for Loop without List

Python program to find largest of n numbers using for loop without list is provided on this page.

Python Program To Find Largest Of N Numbers Using For Loop Without List

We can find largest of n numbers using built in function max() but it we are supposed to use for loop so cannot use max() here.

We have to store numbers somehow so excluding list available options are dictionary, set etc.

We will use set.


numbers = {1, 2, 3, 4, 5}

# variable to store the largest number
largest = None
for number in numbers:
	if largest == None:
		largest = number
	elif number > largest:
		largest = number


print("Largest of N numbers is " , largest)

Related To Python

Comments