Input 10 numbers in integer array and find largest and the smallest number position in Python
Arrays - Question 3
In this question, we will see how to input 10 numbers in integer array and find the position of the largest and the smallest number in Python programming. To know more about arrays click on the arrays lesson.
Q3) Write a program in Python to input 10 numbers in integer array and find the position of the largest and the smallest number.
Program
from array import *
ln=0; lnp=0; sn=0; snp=0
a=array('i',[])
print('Enter 10 numbers')
for i in range(10):
a.append(int(input()))
for i in range(10):
if i==0:
ln=a[i]
sn=a[i]
lnp=i
snp=i
elif a[i]>ln:
ln=a[i]
lnp=i
elif a[i]<sn:
sn=a[i]
snp=i
print('Largest Number Position = %d' %(lnp+1))
print('Smallest Number Position = %d' %(snp+1))
Output
Enter 10 numbers 63 12 57 61 98 11 3 4 75 82 Largest Number Position = 5 Smallest Number Position = 7