When using python3.5.3 getting KeyError 0:0












0















we are kind of new to coding with python3 and we have been successful using other scripts, but trying to set up this wind vane is not working for us, using a list in python3. Any help is greatly appreciated if anyone can point my 10 year old and I in the right direction. We are getting a KeyError 0:0 after reading line 36 (print directive) Here is our code:



 from gpiozero import MCP3008
import time
adc = MCP3008(channel=1)
import math
wind = 0
values =
volts = {
0.4: 0.0,
1.4: 22.5,
1.2: 45.0,
2.8: 67.5,
2.7: 90.0,
2.9: 112.5,
2.2: 135.0,
2.5: 157.5,
1.8: 180.0,
2.0: 202.5,
0.7: 225.0,
0.8: 247.5,
2.8: 67.5,
2.7: 90.0,
2.9: 112.5,
2.2: 135.0,
2.5: 157.5,
1.8: 180.0,
2.0: 202.5,
0.7: 225.0,
0.8: 247.5,
0.1: 270.0,
0.3: 292.5,
0.2: 315.5,
0.6: 337.5
}

while True:
wind = round (adc.value * 3.3,1)
if not wind in volts:
print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
else:
print('found ' + str(wind) + ' ' + str(volts[wind]))


Error we are getting:



 File "direction-test.py", line 36, in <module>
print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
KeyError: 0.0









share|improve this question





























    0















    we are kind of new to coding with python3 and we have been successful using other scripts, but trying to set up this wind vane is not working for us, using a list in python3. Any help is greatly appreciated if anyone can point my 10 year old and I in the right direction. We are getting a KeyError 0:0 after reading line 36 (print directive) Here is our code:



     from gpiozero import MCP3008
    import time
    adc = MCP3008(channel=1)
    import math
    wind = 0
    values =
    volts = {
    0.4: 0.0,
    1.4: 22.5,
    1.2: 45.0,
    2.8: 67.5,
    2.7: 90.0,
    2.9: 112.5,
    2.2: 135.0,
    2.5: 157.5,
    1.8: 180.0,
    2.0: 202.5,
    0.7: 225.0,
    0.8: 247.5,
    2.8: 67.5,
    2.7: 90.0,
    2.9: 112.5,
    2.2: 135.0,
    2.5: 157.5,
    1.8: 180.0,
    2.0: 202.5,
    0.7: 225.0,
    0.8: 247.5,
    0.1: 270.0,
    0.3: 292.5,
    0.2: 315.5,
    0.6: 337.5
    }

    while True:
    wind = round (adc.value * 3.3,1)
    if not wind in volts:
    print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
    else:
    print('found ' + str(wind) + ' ' + str(volts[wind]))


    Error we are getting:



     File "direction-test.py", line 36, in <module>
    print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
    KeyError: 0.0









    share|improve this question



























      0












      0








      0








      we are kind of new to coding with python3 and we have been successful using other scripts, but trying to set up this wind vane is not working for us, using a list in python3. Any help is greatly appreciated if anyone can point my 10 year old and I in the right direction. We are getting a KeyError 0:0 after reading line 36 (print directive) Here is our code:



       from gpiozero import MCP3008
      import time
      adc = MCP3008(channel=1)
      import math
      wind = 0
      values =
      volts = {
      0.4: 0.0,
      1.4: 22.5,
      1.2: 45.0,
      2.8: 67.5,
      2.7: 90.0,
      2.9: 112.5,
      2.2: 135.0,
      2.5: 157.5,
      1.8: 180.0,
      2.0: 202.5,
      0.7: 225.0,
      0.8: 247.5,
      2.8: 67.5,
      2.7: 90.0,
      2.9: 112.5,
      2.2: 135.0,
      2.5: 157.5,
      1.8: 180.0,
      2.0: 202.5,
      0.7: 225.0,
      0.8: 247.5,
      0.1: 270.0,
      0.3: 292.5,
      0.2: 315.5,
      0.6: 337.5
      }

      while True:
      wind = round (adc.value * 3.3,1)
      if not wind in volts:
      print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
      else:
      print('found ' + str(wind) + ' ' + str(volts[wind]))


      Error we are getting:



       File "direction-test.py", line 36, in <module>
      print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
      KeyError: 0.0









      share|improve this question
















      we are kind of new to coding with python3 and we have been successful using other scripts, but trying to set up this wind vane is not working for us, using a list in python3. Any help is greatly appreciated if anyone can point my 10 year old and I in the right direction. We are getting a KeyError 0:0 after reading line 36 (print directive) Here is our code:



       from gpiozero import MCP3008
      import time
      adc = MCP3008(channel=1)
      import math
      wind = 0
      values =
      volts = {
      0.4: 0.0,
      1.4: 22.5,
      1.2: 45.0,
      2.8: 67.5,
      2.7: 90.0,
      2.9: 112.5,
      2.2: 135.0,
      2.5: 157.5,
      1.8: 180.0,
      2.0: 202.5,
      0.7: 225.0,
      0.8: 247.5,
      2.8: 67.5,
      2.7: 90.0,
      2.9: 112.5,
      2.2: 135.0,
      2.5: 157.5,
      1.8: 180.0,
      2.0: 202.5,
      0.7: 225.0,
      0.8: 247.5,
      0.1: 270.0,
      0.3: 292.5,
      0.2: 315.5,
      0.6: 337.5
      }

      while True:
      wind = round (adc.value * 3.3,1)
      if not wind in volts:
      print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
      else:
      print('found ' + str(wind) + ' ' + str(volts[wind]))


      Error we are getting:



       File "direction-test.py", line 36, in <module>
      print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))
      KeyError: 0.0






      python-3.x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 '18 at 0:35







      Joe

















      asked Nov 25 '18 at 23:45









      JoeJoe

      12




      12
























          1 Answer
          1






          active

          oldest

          votes


















          1














          volts[wind] gets the value of the wind key in the volts dictionary. For example, if wind = 0.4, volts[wind] gets the value 0.0 from the volts dictionary.



          if not wind in volts:
          print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))


          In your code above, you're checking to see if not wind in volts: and when it finds that the key is not in the dictionary, you're trying to print the non-existent key's value in line 38.



          In short, remove str(volts[wind]) from line 38 to get rid of the KeyError. You can find a little more about Python dictionaries here.






          share|improve this answer


























          • Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

            – Joe
            Nov 26 '18 at 0:53











          • @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

            – Jordan
            Nov 26 '18 at 1:20











          • Ok, thank you so much!

            – Joe
            Nov 26 '18 at 2:33











          • Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

            – Joe
            Dec 9 '18 at 3:13











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473145%2fwhen-using-python3-5-3-getting-keyerror-00%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          volts[wind] gets the value of the wind key in the volts dictionary. For example, if wind = 0.4, volts[wind] gets the value 0.0 from the volts dictionary.



          if not wind in volts:
          print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))


          In your code above, you're checking to see if not wind in volts: and when it finds that the key is not in the dictionary, you're trying to print the non-existent key's value in line 38.



          In short, remove str(volts[wind]) from line 38 to get rid of the KeyError. You can find a little more about Python dictionaries here.






          share|improve this answer


























          • Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

            – Joe
            Nov 26 '18 at 0:53











          • @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

            – Jordan
            Nov 26 '18 at 1:20











          • Ok, thank you so much!

            – Joe
            Nov 26 '18 at 2:33











          • Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

            – Joe
            Dec 9 '18 at 3:13
















          1














          volts[wind] gets the value of the wind key in the volts dictionary. For example, if wind = 0.4, volts[wind] gets the value 0.0 from the volts dictionary.



          if not wind in volts:
          print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))


          In your code above, you're checking to see if not wind in volts: and when it finds that the key is not in the dictionary, you're trying to print the non-existent key's value in line 38.



          In short, remove str(volts[wind]) from line 38 to get rid of the KeyError. You can find a little more about Python dictionaries here.






          share|improve this answer


























          • Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

            – Joe
            Nov 26 '18 at 0:53











          • @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

            – Jordan
            Nov 26 '18 at 1:20











          • Ok, thank you so much!

            – Joe
            Nov 26 '18 at 2:33











          • Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

            – Joe
            Dec 9 '18 at 3:13














          1












          1








          1







          volts[wind] gets the value of the wind key in the volts dictionary. For example, if wind = 0.4, volts[wind] gets the value 0.0 from the volts dictionary.



          if not wind in volts:
          print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))


          In your code above, you're checking to see if not wind in volts: and when it finds that the key is not in the dictionary, you're trying to print the non-existent key's value in line 38.



          In short, remove str(volts[wind]) from line 38 to get rid of the KeyError. You can find a little more about Python dictionaries here.






          share|improve this answer















          volts[wind] gets the value of the wind key in the volts dictionary. For example, if wind = 0.4, volts[wind] gets the value 0.0 from the volts dictionary.



          if not wind in volts:
          print('Unknown value ' + str(wind) + ' ' + str(volts[wind]))


          In your code above, you're checking to see if not wind in volts: and when it finds that the key is not in the dictionary, you're trying to print the non-existent key's value in line 38.



          In short, remove str(volts[wind]) from line 38 to get rid of the KeyError. You can find a little more about Python dictionaries here.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 26 '18 at 20:26

























          answered Nov 25 '18 at 23:59









          JordanJordan

          707




          707













          • Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

            – Joe
            Nov 26 '18 at 0:53











          • @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

            – Jordan
            Nov 26 '18 at 1:20











          • Ok, thank you so much!

            – Joe
            Nov 26 '18 at 2:33











          • Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

            – Joe
            Dec 9 '18 at 3:13



















          • Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

            – Joe
            Nov 26 '18 at 0:53











          • @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

            – Jordan
            Nov 26 '18 at 1:20











          • Ok, thank you so much!

            – Joe
            Nov 26 '18 at 2:33











          • Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

            – Joe
            Dec 9 '18 at 3:13

















          Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

          – Joe
          Nov 26 '18 at 0:53





          Ok, do you mean a non-existent voltage value? I did comment out section "+ ' ' + str(volts[wind]))" just to see what happened and it did print the unknown value. I guess we are wondering if there is something wrong with the code or if our voltage value is non-existent causing the error? It seems more like code to us. Thank you so far, we really appreciate it.

          – Joe
          Nov 26 '18 at 0:53













          @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

          – Jordan
          Nov 26 '18 at 1:20





          @Joe, I added a bit more to my answer, plus a link that may be helpful for learning about Python dictionaries. Good luck!

          – Jordan
          Nov 26 '18 at 1:20













          Ok, thank you so much!

          – Joe
          Nov 26 '18 at 2:33





          Ok, thank you so much!

          – Joe
          Nov 26 '18 at 2:33













          Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

          – Joe
          Dec 9 '18 at 3:13





          Ok, I did get this working somewhat, but I am trying to upload the darn thing to Weather Underground and having a hard time. I will post more tomorrow. Thanks.

          – Joe
          Dec 9 '18 at 3:13




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53473145%2fwhen-using-python3-5-3-getting-keyerror-00%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin