0

Plz solve if you can.

I want that. User give input from1to12 And code will print string from dictionary. https://code.sololearn.com/cyHIZ41J9Q8m/?ref=app

29th May 2021, 9:12 AM
Aayush Jat
Aayush Jat - avatar
5 odpowiedzi
+ 4
.get is a method for the dictionary. Its first argument is a key and the second is the default for when the key doesn't exist. .get won't result in an error if the key doesn't exist. It is similar to the following code; if v3 in v2: print(v2[v3]) else: print("sorry only 12 months are exist in calender")
29th May 2021, 9:33 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
v2 = { "1":"31", "2":"28","3":"31","4":"30","5":"31","6":"30","7":"31","8":"31","9":"30","10":"31" ,"11":"30","12":"31" } v3 = input( ) print(v2.get(v3, "sorry only 12 months are exist in calender"))
29th May 2021, 9:20 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
I am beginner And i dont know what is (.get) in python Can you fix this problem in my standerd
29th May 2021, 9:24 AM
Aayush Jat
Aayush Jat - avatar
+ 1
Aayush Jat .get() is a function which returns value based on key from dictionary. So there are two methods .get(key) //in this case you will get None if key is not exist in dictionary .get(key, defaultValue) //in this case default value will be return when there is no key in dictionary. diction = {"1" : 31, "2" : 28} diction.get("1") //returns 31 diction.get("3", 31) //returns 31
29th May 2021, 9:30 AM
A͢J
A͢J - avatar
+ 1
https://code.sololearn.com/cyHIZ41J9Q8m/?ref=app I m not calling function so why it is taking input
29th May 2021, 10:19 AM
Aayush Jat
Aayush Jat - avatar