Previous episode: 11. Operate on a List
Next episode: 13. Understand Null Safety
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
In the last episode, you learned about lists. Now it's time to put your new found knowledge to the test. In this challenge, I want you to create a list called grades. The grades should be 82, 76, 88, and 92. I want you to store those values in a list, then calculate the average on those values. Pause the video and give it a shot. (upbeat music) How'd that challenge go for you? Feel free to follow along. Now, keep in mind, there are lots of ways to do the same thing in programming, so your solution may look different than mine. Let's start by creating a new list. Now, at this point, we should add the total. Now let's determine the average. And that's it, let's print out the results. And, with that, we have an average of 84.5, but things are just getting started. Okay, so how'd that go for you? Well, I have another challenge for you. We use brackets to get the first and last item of a list, but we have properties as well. I want you to replace the brackets with properties instead. Use the first property and the last property. Finally, when you divide, to determine the average, use the length property of the list. Pause the video and give it a shot. (upbeat music) Okay, we'll start with the sum variable. Instead of using grades, let's change that to the first item in the grades list. Now do the same for the last element. This time, instead of using grades, let's use the last method. Finally, let's update the average to use the length of the list. Believe it or not, that's it. We're using properties in place of hard coding values, but we get the same result. Nice work.
All videos. All books.
One low price.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.