Problem 60822. Calculate the Number of Moles
The number of moles of a substance is calculated using the formula:
Mass (g) = Moles / Molar Mass (g/mol)
Write a function calculate_moles(mass, molar_mass) that takes:
- mass (in grams) of a substance
- molar_mass (its molar mass in g/mol)
and returns the number of moles, rounded to three decimal places.
Solution Stats
Problem Comments
-
1 Comment
Christian Schröder
on 19 Mar 2025 at 18:55
Mass is moles times molar mass, not moles divided by molar mass - or perhaps you meant to write Moles = Mass (g) / Molar Mass (g/mol).
Also, the test suite expects solutions to return 0 when a molar mass of zero is provided, not Inf.
Solution Comments
Show commentsProblem Recent Solvers4
Suggested Problems
-
4 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!