Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Krishnan Sampath
Courses Plus Student 1,115 PointsDoubt in Python Sequence Challenge Task 1
Question :
Create a slice of the provided student_gpas list that includes the 3rd through the 5th elements in the list. Assign the slice to a variable called sliced_gpas.
student_gpas = [4.0, 2.3, 3.5, 3.7, 3.9, 2.8, 1.5, 4.0] sliced_gpas=student_gpas[3:5] print (sliced_gpas)
I am getting the below error
Bummer: Whoops, looks like your slice contains incorrect values. Remember that slices are exclusive of the stop value.
Please let me know what was wrong in this code ?
1 Answer
Steven Parker
243,253 PointsThe hint about "exclusive of the stop value" is trying to remind you that the stop value must be higher than the last index you want in the slice
So instead of "student_gpas[3:5]", you need "student_gpas[3:6]" to get "the 3rd through the 5th elements in the list".
Also, the instructions don't say anything about using "print".