Ok, this sounds suspiciously like a homework question.
The whole point of homework is that you learn by figuring it out for yourself...
If someone gives you the answer, you don't learn anything.
So... do the steps... THINK about the problem until you understand it well enough to DESCRIBE it in point form. Then PLAN your solution deciding what functions, variables, etc. you need so you can WRITE your code.
If you run into troble with your code, post it here and we'll see what we can do.