How it Works

How the Calculator Script Works

The script starts inside the while True loop, prompting you with "Enter volts: ".  The characters you type are stored in the text variable.  Then V = float(text) converts the characters you have typed from text into a floating point value and stores the result in a variable named V.  It repeats those steps for loading the ohms value you enter into the variable R.

while True:
    text = input("Enter volts: ")
    V = float(text)
    text = input("Enter ohms: ")
    R = float(text)   
 

 

Since V and R are known, the I = V / R form of the Ohm’s Law equation calculates the current value I.

   I = V / R    

 

After printing "I = ", the value of I, and the “A” unit, the script prints an empty line.  After that, the while True loop repeats so that you can calculate another current value.

   print("I = ", I, "A")
   print()    

 

Try This: Calculate V from A and Ω

Try modifying your script to calculate volts from amps and ohms.

 

  • Modify your script as shown below.
  • Update the name in the Script Name field to calculate_v_from_i_and_r.  Then , click Load/SaveDownload Project Hex to save a copy of your work.
  • Click Connect and select the micro:bit and connect if a popup appears.
  • Click Flash to load the script into the micro:bit.
  • Click Open Serial, and try entering some of the measurements you have taken previously to verify that they match the calculated values.