Why is the code not working | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

15th Feb 2022, 10:06 PM
Madueke Anthony Chinedu
Madueke Anthony Chinedu - avatar
4 Answers
+ 4
The index in curly brackets starts with 0. Change the 3 in the curly brackets to 0 and it will work
15th Feb 2022, 10:28 PM
Slick
Slick - avatar
+ 4
msg = "Numbers: {2} {0} {1}". format(nums[3], nums[1], nums[2])
15th Feb 2022, 10:38 PM
Solo
Solo - avatar
+ 1
nums = [4, 5, 6, 9, 15, 81] msg = "Numbers: {3} {1} {2}". format(nums[0], nums[1], nums[2], nums[3]) print(msg)
15th Feb 2022, 10:37 PM
Juan Diego Durán Estrada
Juan Diego Durán Estrada - avatar
+ 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
16th Feb 2022, 6:09 AM
Ipang