You posed
this same question ealier and OriginalGriff kindly outlined the logic for you, yet you have shown no attempt to implement that logic.
So I say: No, you do not need the code because you are a beginner, but you want some-else to write it for you because you are too lazy to make an attempt at doing your own work.
Show some initiative by writing some code. If you are unable to get it to perform as you want, then ask for help with showing your code and explaining what is not working the way you want it to.