0
Why is the code not working
I change the integer in the curly brackets, after adding some variable in the list. But I keep getting error MSG's. https://code.sololearn.com/csaZBDzQokVk/?ref=app
4 Answers
+ 4
The index in curly brackets starts with 0. Change the 3 in the curly brackets to 0 and it will work
+ 4
msg = "Numbers: {2} {0} {1}". format(nums[3], nums[1], nums[2])
+ 1
nums = [4, 5, 6, 9, 15, 81]
msg = "Numbers: {3} {1} {2}". format(nums[0], nums[1], nums[2], nums[3])
print(msg)
+ 1
As Slick said, the numbers in curly brackets are zero-based indices of the arguments given for format() function.
msg = "Numbers: {0} {1} {2}". format(nums[3], nums[1], nums[2])
Notice that 0, 1, and 2 were used as indices (numbers in curly brackets). Then look at arguments of format() function
nums[3] # first argument, index 0
nums[1] # second argument, index 1
nums[2] # third argument, index 3