Infosys interview question

Write code for certain conditions