+ 1

#dictionary d={"mayukh":"9/11/2005", "puneet":"10/11/2005"} word=(input ("enter your word")) print (d (word))

Can anyone tell me the mistake in the program ?? https://code.sololearn.com/c2gB6FiLBIzL/?ref=app

1st Nov 2022, 12:28 PM
Puneet Kumar
Puneet Kumar - avatar
6 ответов
+ 9
Puneet Kumar , see your code slightly modified, see also the comments. #dictionary d={"mayukh":"9/11/2005", "puneet":"10/11/2005"} # we need to turn your first line into 2 lines word=(input ("enter your word: ")) # inserted a space + : at the end of the string if word in d: # add this to make sure that the input string can be found as a key in the dictionary print(d[word])
1st Nov 2022, 2:51 PM
Lothar
Lothar - avatar
+ 6
You code is incomplete/ the indentation is messed up. Please DO NOT put code in the title section. It gets cut off. LINK your code instead.
1st Nov 2022, 12:42 PM
Lisa
Lisa - avatar
+ 6
Please link your code so we can test it and look for the issue.
1st Nov 2022, 12:55 PM
Lisa
Lisa - avatar
+ 4
Use square brackets to get value by key from dictionary. Wrong : print(d(word)) Correct : print(d[word])
1st Nov 2022, 12:49 PM
Aditya Dhiman
Aditya Dhiman - avatar
+ 4
Like Aditya said you can use the square bracket to do it, but if you use the square bracket when it won't find the key, it will return a key error. Instead, you can use the .get() method to get the desired input if the key doesn't exist then it by default returns None instead of a key error. You can also set the default value in the second parameter in the get method(). An example: https://code.sololearn.com/cv790Op6fmcm?ref=app
1st Nov 2022, 1:07 PM
The future is now thanks to science
The future is now thanks to science - avatar
0
Ok
2nd Nov 2022, 3:52 PM
Asim Farheen ⭐⭐🤺👿👿
Asim  Farheen ⭐⭐🤺👿👿 - avatar