While taking a viva class teacher decides to take the viva of two roll numbers at a time.
For this she calls the roll numbers from roll numbers list as : one roll number from 1st nth roll number and 2nd roll number from the nth last roll number. For example if the numbers are : roll-num=[21,23,45,6,7,23,9,11,15,18] and n=3. One roll number calls 45 for viva and
second roll number called 11 for viva. Write a python function CRN(X, n) which take a list X and nth roll no. as input and returns 1st nth roll no. and 2nd roll no. from nth last roll no.
If nth roll number does not lie in range of the list the function will return "n not in range" in place of 1st roll no. and empty string " " in place of 2nd roll number. Give fixed input .
list =[21,23,45,6,7,23,9,11,15,18]
roll_num= list
n=3
X= list
def CRN(X,n):
return (X[n-1])
# To print the third index from the list
try:
print ( " The first roll number for viva is:", X[n-1])
# To print the third last index from the list
print ( " The second roll number for viva is:", X[-n])
except IndexError:
# To print that the value is not in range
print ( "n is not in range ")
print ( " Empty string
Comments
Leave a comment