Skip to content
Parallax Learn

Parallax Learn

  • Welcome
  • Tutorials
        • Tutorial Series head tag

          Tutorial Series
        • Tutorial Series

          The special, classroom-ready series pages are organized collections of tutorials for our most popular hardware and/or languages. The tutorials for each topic are conveniently accessible from a single page, shown in the order it is recommended that they be completed.
        • Robotics Series Head tag

          Robotics Series
        • Robotics Series

          • Artificial Intelligence
          • Cybersecurity: Radio Data tutorialCybersecurity
          • cyber:bot + Python
          • cyber:bot + MakeCode
          • Boe-Bot Tutorial SeriesBoe-Bot
          • Arduino Shield-Bot
          • ActivityBot with C TutorialsActivityBot + C
          • ActivityBot with BlocklyProp Tutorial SeriesActivityBot + BlocklyProp
          • Scribbler 3 Tutorial SeriesScribbler 3
        • Electronics & Programming Series Head tag

          Electronics & Programming Series
          • BS2 Board of Education Tutorial SeriesBS2 Board of Education
          • Propeller C-Language BasicsPropeller C Basics
          • FLiP Try-It Kit C Tutorial SeriesFLiP Try-It Kit + C
          • FLiP Try-It Kit BlocklyProp TutorialsFLiP Try-It Kit + BlocklyProp
          • Badge WX Tutorial SeriesBadge WX
          • Propeller BlocklyProp Basics and ProjectsPropeller BlocklyProp Basics
          • View All Tutorial Series »
        • Browse Tutorials
        • Browse Tutorials

          Individual tutorials sorted by robot or kit, and language.
        • By Robot or Kit
          • ActivityBot
          • SumoBot WX
          • Boe-Bot
          • Shield-Bot
          • cyber:bot
          • Badge WX
          • ELEV-8
          • ARLO
        • By Language
        • By Language

          • Propeller C
          • Arduino
          • BlocklyProp
          • PBASIC
          • Python
          • MakeCode
          • View All Tutorials »
  • Educators
  • Reference
  • Downloads
  • Home
  • All Courses

Dictionary Primer

Curriculum

  • 1 Section
  • 4 Lessons
  • Lifetime
Expand all sectionsCollapse all sections
  • Dictionary Primer
    4
    • 1.0
      About Dictionaries
    • 1.1
      Create a Dictionary
    • 1.2
      Try This: Use Keys to Change Values
    • 1.3
      Your Turn: Expand and Use the Dictionary

Your Turn: Expand and Use the Dictionary

  • Change project’s name from  interactive_dictionary_try_this to interactive_dictionary_your_turn.
  • Add these statements to the end of the script you’ve been building.
  • Save the modified script.
  • Click the Send to micro:bit button.
text = input("Enter score to reach next week: ")
value = int(text)

info['goal'] = value

print("Updated dictionary")
print("info = ", info)

text = info['score']
score = int(text)

text = info['goal']
score_goal = int(text)

difference = score_goal - score

print("That's", difference, "points more.")
  • Click the the right of the Enter your name: prompt in the serial monitor.
  • To make it match the example shown here, enter the same values as before, and then enter 2000 when prompted to enter the score to reach next week.
  • Verify that the updated dictionary that gets displayed is info = {’goal’: 2000, ’score’ : 1234, ’name’: ’Sir Lancelot’}.
  • Verify that it displays That’s 766 points more.

Look what happened to the key-value pairs.  The MicroPython runtime interpreter changed the order when you added the goal’: 2000 pair.  Again, that change in order did not matter because the script used the ’score’ and ’goal’ keys to look up the values that got stored in the score and score_goal variables.  Then, the script used these values to correctly calculate:

    difference = score_goal – score
               = 2000 – 1234
               = 766.  

 


Printer-friendly version
Try This: Use Keys to Change Values
Prev

DISCUSSION FORUMS | PARALLAX INC. STORE

About | Terms of Use | Feedback: learn@parallax.com | Copyright©Parallax Inc. 2024

© 2026 Parallax Learn • Built with GeneratePress