How to make a code for this ?

Hi there and welcome to Community!

This looks like a homework problem, so instead of doing the work for you I'd rather try to walk you through the process so that you can learn and make the most of it. For starters, what have you tried already? Where are you getting stuck?

The below link is a great start for asking these kinds of questions so that you're able to get the greatest benefit from everyone's help!