TO LEARN PYTHON :LEARN
1.
Problem Statement
The median of a list of numbers is essentially it's middle element after sorting. The same number of elements occur after it as before. Given a list of numbers with an odd number of elements, can you find the median ?
Input Format
The first line contains the integer n, the size of arr.
The second line contains space-separated integers arri.
Output Format
Output one integer, the median.
PYTHON CODE:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
print(a[n//2])
************************************************************************************
2.
This is a simple challenge to get things started. Given a sorted array (arr) and a number (V), can you print the index location of V in the array? Input Format The first line contains an integer, V, a value to search for. The next line contains an integer, n. the size of arr. The last line contains n space-separated integers, each a value of arri where O<=i<n Output Format Output the index of V in the array.
python code:
a=int(input())
b=int(input())
A=list(map(int,input().split()))
print(A.index(a))
**************************************************************************************
Post a Comment