HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
  1. Python Labs
  2. /A Bragg's law toolkit
ChemistryMediumHigh School (11–12)Solid State

A Bragg's law toolkit

You will write four functions that do the sums of X-ray diffraction for cubic crystals.

The idea. Bragg's law is nλ=2dsin⁡θn\lambda = 2d\sin\thetanλ=2dsinθ. In a cubic cell, dhkl=a/h2+k2+l2d_{hkl} = a/\sqrt{h^2 + k^2 + l^2}dhkl​=a/h2+k2+l2​. A bcc lattice reflects only when h+k+lh + k + lh+k+l is even. An fcc lattice reflects only when hhh, kkk and lll are all odd or all even.

Your tasks.

  1. Complete d_spacing(a, h, k, l).
  2. Complete two_theta(d, wavelength, n) so that it returns 2θ2\theta2θ in degrees, or None when there is no reflection.
  3. Complete allowed(lattice, h, k, l) for "sc", "bcc" and "fcc".
  4. Complete first_lines(lattice, a, wavelength) so that it returns the 2θ2\theta2θ of the first four allowed reflections in order. The candidate planes are given.

Run it first, just as it is. The checker at the end prints FAIL for each task. Then do the tasks one at a time, and run the program again after each one. A Hint appears under every check that still fails.

When every line says PASS, print first_lines("bcc", 286.65, 154.06). These are the lines of iron.

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A worked solution

Run your code once to unlock the worked solution.

Have you tried it?

Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.

Log in to save
← All Labs
← A defect calculatorAn indexing machine →
More onSolid State

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. An indexing machineHard
  2. A defect calculatorMedium
  3. Ionic structures from their radiiMedium
  4. Formulas from voidsMedium
  5. A cubic cell calculatorMedium
All labs on this topic →