Hi there! I’m currently working on the Frida Kahlo project on my computer and I’m on Task 6. I’ve successfully created a list that contains the IDs of each painting called audio_tour_number
, here is what I did:
# Task 5
paintings_length = len(paintings) + 1
# Task 6
audio_tour_number = []
for i in range(1, paintings_length):
audio_tour_number.append(i)
I’m on the right track with my approach, but I’ve noticed that the generated list only has six elements instead of seven so I fixed it by adding one to the length. Can you provide me with some advice on whether there is a more effective method? I would appreciate your help, I’m confident that I’ll be able to get it right with your assistance.
I’m confused why you added 1 to the length of the list of paintings when the question asks you to find the length of the list, which would be:
len(paintings)
>>7
You only get 6 items b/c the length of the list of paintings is 7 items, plus, you’re starting at index 1. So, your 2 parameters start at index 1 and stop at the length of the list of paintings.
The built in range()
function has 3 parameters, start, stop, step=. (The 3rd is optional).
For task 6, if you want to generate a list of numbers, wouldn’t this suffice? Remember, one of the ways to create a list is to use the built-in list()
function (which is actually a type constructor).
audio_tour_number = list(range(1, 8)) #to get a list of 7 numbers, you go one index beyond.
print(audio_tour_number)
>[1, 2, 3, 4, 5, 6, 7]