Computer Science, asked by sandhya13403, 4 months ago

What will be the output after the following statements?
x= {'year': 2016, 'month': 'March'}
if 'day' not in x
x[day'] = 'Tuesday'
print(x)
(a) ('day', 'Tuesday)
(b) {'day': 'Tuesday', 'month': 'March'}

(c) 'day': 'Tuesday', 'month': 'March',
'year': 2016

(d) {'day': 'Tuesday', 'month': 'March',
'year': 2016​

Answers

Answered by allysia
35

Correcting the code a bit to,

x= \{ "year":2016, "month":"march"\} \\\tt{ if \  "day" \ not \  in\    x:} \\\tt {\qquad x["day"] \ = \ "Tuesday" } \\\tt  print(x)

The result should be :

\tt x \ = \  \{ "year" \ : \ 2016 \ ,  \ "  month"\ : \ " March" \ ,\ "day"\ : \ "Tuesday" \}\\\tt

which is now of the options but if I had to chose I'll go with (d) with com correction of course as since all the elements are there but the indices are wrong.

\tt x \ = \  \{ \ "day"\ : \ "Tuesday"\ , \ "  month"\ : \ " March"\  , \ "year" \ : \ 2016 \  \}

Explanation:

dictionary ["key"] = "value" adds a key-value pair in the end of the dictionary.

Answered by jai696
19

The output will be {'year': 2016, 'month': 'March', 'day': 'Tuesday'}

Explanation:

As the key day doesn't exist in dict x, it will create it with the value Tuesday

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions