Answer to Question #296561 in Python for Piyush

Question #296561

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 .


1
Expert's answer
2022-02-11T18:37:39-0500
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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS