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. /An indexing machine
ChemistryHardHigh School (11–12)Solid State

An indexing machine

You will write a program that indexes the powder pattern of a cubic crystal from a list of 2θ2\theta2θ values.

The idea. For each line, sin⁡2θ\sin^2\thetasin2θ is proportional to h2+k2+l2h^2 + k^2 + l^2h2+k2+l2. Divide every sin⁡2θ\sin^2\thetasin2θ by the first, then try the factors 1, 2 and 3. The right factor turns all the ratios into whole numbers. The whole numbers name the lattice: simple cubic starts 1,2,3,41, 2, 3, 41,2,3,4, bcc 2,4,6,82, 4, 6, 82,4,6,8 and fcc 3,4,8,113, 4, 8, 113,4,8,11. The edge is a=λh2+k2+l2/(2sin⁡θ)a = \lambda\sqrt{h^2 + k^2 + l^2}/(2\sin\theta)a=λh2+k2+l2​/(2sinθ).

Your tasks.

  1. Complete sin2(two_theta) so that it returns sin⁡2θ\sin^2\thetasin2θ.
  2. Complete whole_numbers(angles) so that it returns the list of whole numbers for the first factor (1, 2 or 3) that makes every ratio within 0.05 of a whole number.
  3. Complete lattice(sums) so that it returns "fcc", "bcc" or "sc" from the first two sums.
  4. Complete edge(two_theta, s, wavelength).

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, index the lead pattern [31.27, 36.27, 52.23, 62.14] and find its edge.

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 Bragg's law toolkitFreundlich constants from a table →
More onSolid State

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. A Bragg's law toolkitMedium
  2. A defect calculatorMedium
  3. Ionic structures from their radiiMedium
  4. Formulas from voidsMedium
  5. A cubic cell calculatorMedium
All labs on this topic →