You've just taken code that someone else wrote for you and that doesn't conform to the requirements. Why don't you start by
1. Reading the requirements
2. Working out how to break the task down into small steps
3. Working out how to implement each of those small steps
You've been given some example data to work with, so as mentioned above, why don't you hard code it in your program and use that to get you going? This is pretty much what I'd do in the real world - take my example, write a test case including it and work on getting that to pass (I'm not suggesting you write tests here, because that might be out of scope for you right now, but I'm more saying it to illustrate how we work).
Also, if you're unable to even break down relatively simple problems like this, I have no idea how you're going to try and build a web application, which is a much more complex problem.
1. Reading the requirements
2. Working out how to break the task down into small steps
3. Working out how to implement each of those small steps
You've been given some example data to work with, so as mentioned above, why don't you hard code it in your program and use that to get you going? This is pretty much what I'd do in the real world - take my example, write a test case including it and work on getting that to pass (I'm not suggesting you write tests here, because that might be out of scope for you right now, but I'm more saying it to illustrate how we work).
Also, if you're unable to even break down relatively simple problems like this, I have no idea how you're going to try and build a web application, which is a much more complex problem.