title: Have a query on Dictionary Topic in Python
body: <p>I am not able to proceed in a program I was practicing in Python. It is about Dictionaries in Python.</p>
  <p>The Question is : Write a python program to check whether the given key is present, if present print the value , else add a new key and value.</p>
  <p>My solution:</p>
  <pre><code>class Pro2:
      def check(self):
          dict = {}
          a=&quot;&quot;
          b=&quot;&quot;
          c=&quot;&quot;
          d=&quot;&quot;
          for x in range(5):
              a=(input(&quot;Enter key: &quot;))
              b=(input(&quot;Enter value: &quot;))
              dict[f&quot;{a}&quot;:f&quot;{b}&quot;]
          c=input(&quot;Enter a key which is to be checked: &quot;)
          if (dict.__contains__(c)):
              print(dict[c])
          else:
              d=input(&quot;Enter the value to be added: &quot;)
              dict[f&quot;{c}&quot;:f&quot;{d}&quot;]
  </code></pre>
  <p>Now the problem occurring is that, the accepted input is not being appended in the respective Dictionary in the 'for' loop.
  Can anybody please help me. Suggestions for better solutions are also accepted.
  Thank You in Advance!</p>