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
Tried it? Did this program work on your calculator?
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.
TI-84 Plus CE Python · screen preview
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
- Enter the moles of solute, then the volume of solution in liters.
- The program shows the division and the molarity.
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
- Use the volume of the finished solution, not the volume of water you started with.
- Convert milliliters to liters: 250 mL is 0.25 L.
- If you are given grams, divide by the molar mass to get moles first.
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
"""DuckieDai Molarity prototype for TI-84 Plus CE Python.Standalone source. Not yet verified on a physical calculator."""def duckiedai_intro(program_name, wait=True):"""Show the same small opening as the Rectangle Area program."""title = program_name[:16]empty = 16 - len(title)left = empty // 2right = empty - leftprint("+----------------------+")print("| " + " " * left + title + " " * right + " |")print("| |")print("| __ |")print("| ___(o )> quack! |")print("| \\ <_. ) |")print("| `---' |")print("| by DuckieDai |")print("+----------------------+")print("Loading...")if wait:input("Press enter to start ")print("\n" * 6)def is_nonnegative_finite(value):return value >= 0 and value < 1e100def nonnegative_number(prompt):"""Zero moles is valid; negative amount is not."""while True:try:value = float(input(prompt))if is_nonnegative_finite(value):return valueexcept ValueError:passprint("Enter 0 or above.")def positive_number(prompt):"""Solution volume in liters must be greater than zero."""while True:try:value = float(input(prompt))if value > 0 and value < 1e100:return valueexcept ValueError:passprint("Enter a number above 0.")def molarity(moles, liters):"""Return amount of solute divided by total solution volume."""if not is_nonnegative_finite(moles):raise ValueError("moles must be nonnegative and finite")if not liters > 0 or not liters < 1e100:raise ValueError("liters must be positive and finite")result = moles / litersif not is_nonnegative_finite(result):raise ValueError("molarity is too large")return resultdef main():duckiedai_intro("MOLARITY")print("MOLARITY")print("Formula: M = mol / L")print("Use solution volume, not")print("solvent volume.")print()moles = nonnegative_number("Moles solute: ")liters = positive_number("Solution L: ")result = molarity(moles, liters)print()print("M = " + str(moles) + " / " + str(liters))print("Molarity =")print(str(result) + " mol/L")print()print("DuckieDai says: done!")# TI-Python imports a selected AppVar instead of setting __name__ to main.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
- 1.0.0 — current version, published . Download this reviewed version
Related learning
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.