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
  • 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 halogen displacement predictor
ChemistryMediumHigh School (9–10)The p-Block Elements › Groups 17 and 18: Halogens and Noble Gases

A halogen displacement predictor

You will write three functions for the displacement of halogens. One decides whether a halogen displaces another. One says what you would see. One finds the moles of halogen made.

The idea. The order of reactivity is chlorine, bromine, iodine, with chlorine the most reactive. A halogen displaces another only if it is higher in the list. Displaced bromine makes the solution orange and displaced iodine makes it brown. In Cl2+2KX→2KCl+X2\text{Cl}_2 + 2\text{KX} \rightarrow 2\text{KCl} + \text{X}_2Cl2​+2KX→2KCl+X2​ two moles of halide make one mole of halogen.

Your tasks.

  1. Complete displaces(halogen, halide). Both arguments are the names of halogens, for example "chlorine" and "bromine" for chlorine water and potassium bromide.
  2. Complete observation(halogen, halide). It returns the colour from the dictionary colour if the halogen displaces the other, and "no reaction" if not.
  3. Complete moles_made(mol_halide). It returns the moles of halogen molecules that form.

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, call observation("bromine", "chlorine"). What do you expect?

StemPy LabContributed by StemPy Lab
python
Loading Python runtime…

A 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 halogen trends calculatorAn error calculator for apparatus →
More onThe p-Block Elements › Groups 17 and 18: Halogens and Noble Gases

Discussion (0)

Log in to join the discussion.

Loading…

More labs on this topic

  1. A halogen trends calculatorEasy
  2. Count the electron pairs and name the shapeMedium
  3. Will the halogen displace the halideEasy
All labs on this topic →