Hidden WordScanner
Private scans · No account required

DuckieDai Molarity

Find molarity by dividing moles of solute by liters of final solution: M = mol / L.

chemistry · MIT License

Overview

Find molarity by dividing moles of solute by liters of final solution: M = mol / L.

  • Tested on a TI calculator
  • Downloaded 43 times
  • Version 1.0.0
  • 2540 bytes
  • No imports

Before you run it

  • TI-84 Plus CE Python · tested on OS 5.8.3, Python App 5.8.3.0048
  • Sent through TI Connect CE to the Python App; the calculator name can be changed during transfer
  • The volume entered is the total final solution volume, not the amount of solvent poured in.
  • Moles cannot be negative, and solution volume must be greater than zero.
  • Inputs and result must remain within the program's finite numeric range.

Try the DuckieDai calculator screen

See the DuckieDai opening, enter moles and liters of final solution, then follow the molarity result.

JavaScript is required for the optional browser simulation. Source viewing and downloading remain available without it.

Simulation boundary: This preview uses a reviewed browser adapter. It does not execute the downloaded Python and does not prove TI-Python or calculator compatibility.

Learn the math

How molarity works

The idea

Molarity measures how concentrated a solution is: the number of moles of dissolved substance in each liter of solution.

It is the concentration unit used in most stoichiometry, titration, and equilibrium problems.

The formula

M = mol / L

M
molarity in moles per liter (mol/L)
mol
moles of solute
L
liters of the final solution

Using the program

Worked example

0.5 mol of sodium chloride is dissolved to make 0.25 L of solution. Enter 0.5 and 0.25.

M = 0.5 / 0.25

The program shows Molarity = 2.0 mol/L.

Tips and common mistakes

Where this comes up

Molarity is introduced in the solutions unit of high school chemistry and is used constantly in general chemistry: dilutions, titrations, stoichiometry in solution, and equilibrium.

Exact reviewed bytes

Source code

Download .py

View source below, copy it when JavaScript is available, or download the exact .py bytes.

  1. """DuckieDai Molarity prototype for TI-84 Plus CE Python.
  2. Standalone source. Not yet verified on a physical calculator.
  3. """
  4. def duckiedai_intro(program_name, wait=True):
  5. """Show the same small opening as the Rectangle Area program."""
  6. title = program_name[:16]
  7. empty = 16 - len(title)
  8. left = empty // 2
  9. right = empty - left
  10. print("+----------------------+")
  11. print("| " + " " * left + title + " " * right + " |")
  12. print("| |")
  13. print("| __ |")
  14. print("| ___(o )> quack! |")
  15. print("| \\ <_. ) |")
  16. print("| `---' |")
  17. print("| by DuckieDai |")
  18. print("+----------------------+")
  19. print("Loading...")
  20. if wait:
  21. input("Press enter to start ")
  22. print("\n" * 6)
  23. def is_nonnegative_finite(value):
  24. return value >= 0 and value < 1e100
  25. def nonnegative_number(prompt):
  26. """Zero moles is valid; negative amount is not."""
  27. while True:
  28. try:
  29. value = float(input(prompt))
  30. if is_nonnegative_finite(value):
  31. return value
  32. except ValueError:
  33. pass
  34. print("Enter 0 or above.")
  35. def positive_number(prompt):
  36. """Solution volume in liters must be greater than zero."""
  37. while True:
  38. try:
  39. value = float(input(prompt))
  40. if value > 0 and value < 1e100:
  41. return value
  42. except ValueError:
  43. pass
  44. print("Enter a number above 0.")
  45. def molarity(moles, liters):
  46. """Return amount of solute divided by total solution volume."""
  47. if not is_nonnegative_finite(moles):
  48. raise ValueError("moles must be nonnegative and finite")
  49. if not liters > 0 or not liters < 1e100:
  50. raise ValueError("liters must be positive and finite")
  51. result = moles / liters
  52. if not is_nonnegative_finite(result):
  53. raise ValueError("molarity is too large")
  54. return result
  55. def main():
  56. duckiedai_intro("MOLARITY")
  57. print("MOLARITY")
  58. print("Formula: M = mol / L")
  59. print("Use solution volume, not")
  60. print("solvent volume.")
  61. print()
  62. moles = nonnegative_number("Moles solute: ")
  63. liters = positive_number("Solution L: ")
  64. result = molarity(moles, liters)
  65. print()
  66. print("M = " + str(moles) + " / " + str(liters))
  67. print("Molarity =")
  68. print(str(result) + " mol/L")
  69. print()
  70. print("DuckieDai says: done!")
  71. # TI-Python imports a selected AppVar instead of setting __name__ to main.
  72. main()
Filename
duckiedai_molarity.py
Size
2540 bytes
SHA-256
fc97f2e47224144e300d273fb015f815d741a8c9f3788f40710cdc71495ba70f

Usage

Inputs

  • Moles of solute: 0 or more, below 1e100
  • Liters of final solution: greater than 0, below 1e100

Outputs

  • Molarity in mol/L, using M = moles / liters

Units: Enter moles of solute and liters of final solution; the result is mol/L. Convert milliliters to liters before entering.

Assumptions and limitations

Assumptions

  • The volume entered is the total final solution volume, not the amount of solvent poured in.

Constraints

  • Moles cannot be negative, and solution volume must be greater than zero.
  • Inputs and result must remain within the program's finite numeric range.

Known failures

  • Negative, non-numeric, NaN, infinite, or out-of-range moles are requested again.
  • Zero, negative, or invalid solution volume is requested again; an excessively large result stops with an error.
  • The answer is not automatically rounded to significant figures or converted from grams or milliliters.

Compatibility and review

Review status
Tested on a TI calculator
Tested on
TI-84 Plus CE Python; OS 5.8.3; Python App 5.8.3.0048; transferred through TI Connect CE as CTEST
What happened
The program ran successfully on the calculator: the duck opening appeared, Enter started the prompts, and the molarity answer displayed. Edge cases were checked on desktop only.
Dependencies
No imports
Suggested calculator name
MOLARITY — you can give it another valid, unique name when you transfer it
Desktop test cases
5 cases

The desktop tests cover calculations and error handling. The calculator review above records what was actually checked on the device.

Transfer and launch

Download the .py file, send it to your calculator with TI Connect CE as MOLARITY or another name, then open the Python App and try the worked example on this page first.

Full installation and troubleshooting guide. Check your teacher's or exam's rules before using any program.

Version history

Did a DuckieDai program help with your homework? Every program here is free. If you would like to say thanks, you can leave a tip on Cash App ($duckiedai214) or read what tips pay for.

Independent compatibility resource: Hidden Word Scanner is independent and is not affiliated with or endorsed by Texas Instruments. TI product names describe compatibility only.

Action-count privacy: Successful downloads, preview starts, and preview completions increment same-origin aggregate counters, and so does a Yes or No answer about whether the program worked. Your browser notes that you answered; that note is never sent to the site. No entered values, source text, IP address, account, cookie, device identifier, or fingerprint is stored with these counts.