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
  • Electrical Measurements

Electrical Measurements

Script and Tests

Values to Metric Prefixes Conversion Script

The values_to_metric_prefixes script converts values to quantities with metric prefixes.  

  • Enter the values_to_metric_prefixes script into the micro:bit Python Editor.
  • Set the project name to values_to_metric_prefixes, then click Save.
  • Click Send to micro:bit.
# values_to_metric_prefixes

prefix_exponents = {'M':6, 'k':3, 'm':-3, 'u':-6}

print("Enter decimal value and metric prefix")
print("Result will be quantity and prefix.")
print()

while True:
    text = input("Enter value: ")
    value = float(text)
    prefix = input("Enter metric prefix: ")
    exponent = prefix_exponents[prefix]
    quantity = value / (10 ** exponent)
    unit = input("Enter unit: ")
    prefix_unit = prefix + unit
    print("Value:", quantity, prefix_unit)
    print()

 

Conversion Script Tests

This script converts decimal values to quantities and metric prefixes.  

  • Click Show serial.
  • Click to the right of the Enter Quantity prompt, type 1 and then press the Enter key.
  • Continue typing the values in the image below  to the right of each prompt, and press Enter after each one.

 

Experiment with Other Values

  • This time, use the values like 0.050 s.  Here are some you will see in upcoming lessons.  Use the expressions on the left, like 50 ms, 38 kHz and so on.  Substitute ohm for Ω and u for µ.  
    • 0.050 s
    • 38,000 Hz
    • 0.0011 A
    • 0.050 V
    • 1000 ohms
    • 0.000010 F

 


Printer-friendly version
How it Works
Prev
Review and Practice
Next

DISCUSSION FORUMS | PARALLAX INC. STORE

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

© 2025 Parallax Learn • Built with GeneratePress