I have this piece of code where it based on this condition:
- Box Color can only be in red, white and black
- If the box's type is A then any color is allowed
- Box's type C is not allowed at all
- For the gift, only green and blue color is allowed and the size cannot be small
- Box and gift color cannot be same
views.py
boxColor = ["red", "white", "black"]
giftColor = ["green", "blue"]
if box.color != gift.color:
if gift.color in giftColor and gift.size != "small":
if (box.type == "A") or (box.type != "C" and box.color in boxColor):
return True
else:
return False
else:
return False
else:
return False
Is there is a way to simplify my code that I can make this more efficient ?
return
statement looks lacking context without adef
, and the title doesn't follow site conventions: Please (re)visit How do I ask a Good Question? \$\endgroup\$