Computer Science, asked by prabhakar8812, 28 days ago

Find the error in following cod.State reason of error

aLst={'a':1, 'b':2, 'c':3}
print (aLst['a' ,'b'])​

Answers

Answered by llEuphoriaBunnyll
406

\huge\fbox\blue{Answer}

The above cod.e will produce KeyError, the reason being that there is no key same as the list ['a' , 'b'] in dictionary aLst.

It seems that the above cod.e intends to print the values of two keys 'a' and 'b', thus we can modify the above cod.e to perform this as:

⟹ aLst={'a':1, 'b':2, 'c':3}

⟹print (aLst['a'] , aLst['b']

\fbox\red{Now it will give this result as:}

\green{1\:\:\:2}

Answered by Mbappe007
30

Answer:

\huge\fbox\blue{Answer}

Answer

The above cod.e will produce KeyError, the reason being that there is no key same as the list ['a' , 'b'] in dictionary aLst.

It seems that the above cod.e intends to print the values of two keys 'a' and 'b', thus we can modify the above cod.e to perform this as:

⟹ aLst={'a':1, 'b':2, 'c':3}

⟹print (aLst['a'] , aLst['b']

\fbox\red{Now it will give this result as:}

Now it will give this result as:

\green{1\:\:\:2}12

Similar questions