Python Online Compiler
Example: Python Program to Find Largest and Smallest Number in an Array using For loop
C
C++
C#
Java
Python
PHP
main.py
STDIN
Run
# Python Program to Find Largest and Smallest Number in an Array using For loop x, s, i, b, sm = [], 0, 0, 0, 0 # x - To store the array list of input numbers # s - To store the size of the array # b - To store the big element variable # sm - To store the small element variable print ("\n-----Enter the size of the array-----") s = int (input ()) print ("\n-----Enter the ", s, " elements of the array-----\n") for i in range (s): x.append(int (input ())) # It stored the first element of the array to check the element b = x[0] for i in range (1, s): # It checks one by one with each value of an array # To compare the value is smallest or largest if b < x[i]: b = x[i] print ("\n-----The largest element is: ", b, "\n") # It stored the first element of the array to check the element sm = x[0] for i in range (1, s): # It checks one by one with each value of an array # To compare the value is smallest or largest if sm > x[i]: sm = x[i] print ("\n-----The smallest element is: ", sm, "\n")
6 73 42 423 42 342 14
Output
Clear
ADVERTISEMENTS