Whats wrong with this code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Whats wrong with this code?

nums = [0,2,3,4] msg = "Points :{0} {2} {3} {4}".format(nums[0],nums[1],nums[2],nums[3]) print(msg)

25th May 2020, 7:58 PM
sofronis
sofronis - avatar
2 Answers
+ 5
The string formatting you use mentions the position {4} which is not provided in the .format method. Remember that Python counts from 0, so {4} means inserting the *fifth* element. And you only provide four in the .format method.
25th May 2020, 8:08 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
ok, i thought that i should put the numbers from the list inside the {}
25th May 2020, 8:15 PM
sofronis
sofronis - avatar