Login and get coding
Check red blood cell compatibility between donor and recipient.
For simplicity, only eight basic types of blood are considered.
The input of blood type can be in the form of:
- Bloodtype enumeration
- An integer value between 0 and 7
- Textual representation e.g. "0-", "B+", "AB+", ...
There are 8 basic blood types based on presence or absence of three antigens: A, B, and Rh-D.
- 0- no antigens
- 0+ Rh-D antigen
- A- antigen A
- A+ antigen A and Rh-D
- B- antigen B
- B+ antigen B and Rh-D
- AB- antigen A and B
- AB+ all 3 antigens (A, B, Rh-D)
An individual who does not have a certain antigen cannot receive a blood from someone who has that antigen.
Blood group 0 individuals do not have A or B antigens. Therefore, a group 0 individual can receive blood only from a group 0 individual, but can donate blood to individual with types A, B, 0 or AB.
Blood group A individuals have the A antigen. Therefore, a group A individual can receive blood only from individuals of groups A or 0, and can donate blood to individuals with type A or AB.
Blood group B individuals have the B antigen. Therefore, a group B individual can receive blood only from individuals of groups B or 0, and can donate blood to individuals with type B or AB.
Blood group AB individuals have both A and B antigens. Therefore, an individual with type AB blood can receive blood from AB0, but cannot donate blood to any group other than AB.
Rh-D negative individuals do not have Rh-D antigen. Therefore, Rh-D negative can receive blood only from other Rh-D negative individuals.
Rh-D positive individuals have Rh-D antigen. Therefore, Rh-D positive individual can receive blood from both Rh-D negative or positive individuals.
Individuals with 0- are universal donors. Individuals with AB+ are universal recipients.
The rules described are general. In practice, there are over 340 different blood-group antigens.
Tasks Complete the function check_bt()
The function should check red blood cell compatibility between a donor and a recipient.
Truefor compatibility between the donor and the recipient,
If the input value is not a required type raise TypeError .
If the input value is not in the defined interval raise ValueError .
279 out of 281 users completed this Bite.
Will you be Pythonista #280 to crack this Bite?
Resolution time: ~76 min. (avg. submissions of 5-240 min.)
Pythonistas rate this Bite 5.92 on a 1-10 difficulty scale.
» Up for a challenge? 💪