Welcome to Project Lovelace! We're still in early development so there are still tons of bugs to find and improvements to make. If you have any suggestions, complaints, or comments please let us know on Discourse, Discord, or GitHub!

Blood types

You will learn about: blood types and complex branching statements

Each person has different blood depending on which antibodies and antigens bind to the surface of their red blood cells. They can be categorized in many different ways, but the two most important are the ABO group system (with four groups: A, B, AB, O) and the Rh blood group system (with two groups: +, -). The chart below shows how you can determine whether blood is suitable for transfusion.

Hospitals have blood banks that collect blood donations and store them until they're needed by patients. Every time a patient needs a blood transfusion, the hospital needs to check that they have some suitable blood that can be accepted by the patient's body. Given a patient's blood type and a list of available blood types figure out if the patient will survive.

Input: The person's blood type as a string, and a list of strings with available blood types.

Output: True if the person can be saved, and false otherwise.

Example 1

Input blood type: "B+" Input list of available blood types: ["A-", "B+", "AB+", "O+", "B+", "B-"] Output survivability: True

Example 2

Input blood type: "AB-" Input list of available blood types: ["O+", "AB+"] Output survivability: False
 Difficulty  Timesink
 Function survive(blood_type, available_blood_types)

You must be logged in to view your submissions.


  • The ABO blood group system categorizes blood by the presence or absence of two oligosaccharides. The A oligosaccharide is present in A blood, the B oligosaccharide is present in B blood, both are present in AB blood, and neither is present in O blood.
  • The Rh blood group system categorizes blood by the presence of the Rh(D) antigen. It's present in + blood, and absent in - blood.
  • There are over 200 rare blood types that can complicate blood transfusions.
  • You could die if your body receives blood that is not suitable.

Let us know what you think about this problem! Was it too hard? Difficult to understand? Also feel free to discuss the problem, ask questions, and post cool stuff on Discourse. You should be able see a discussion thread below. Would be nice if you don't post solutions in there but if you do then please organize and document your code well so others can learn from it.