14_If_Key_does_not_exist.py


Sign up Free. Don't forget to check out our challenges, lessons, solve and learn series and more ...


Code Snippet

#create a dictionary to store teacher's details
d={"Name": "Mr Moose","Subject": "Philosophy","Hobby":"Chess","School House":"Red House"}

def main():
   key=input("Enter key you're searching for:")
   check_key(key)
   if check_key(key):
      print("yes")
   else:
      print("No")
      
def check_key(key):
   if d.get(key):
      return True
   else:
      return None
        
main()
                    

Try it yourself