+ 1

one range, two different results !!

Would you check why I receive two different results by only one range with this 2 codes ? https://code.sololearn.com/cbFl0eZ9zyfR/#py 1 2 3 4 5 6 7 8 9 10 11 and https://code.sololearn.com/cLzRDQ1dqPdi/#py [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

23rd Jan 2018, 5:19 AM
NIMA
NIMA - avatar
2 Respuestas
+ 3
In the first one you are setting i = i + 1. So instead of displaying 0-10, it displays 1-11 because 0+1=1, then i equals 1 and you add one again making it 2, up to 10+1=11. It’s also printing out i on a new line with every iteration, the 2nd uses the same range function but starts at 0 because you’re not adding 1 each time. Also returns a list because you casted it as one. Hope that helps :)
23rd Jan 2018, 5:28 AM
Travis
Travis - avatar
23rd Jan 2018, 5:07 AM
Ankush Kumar
Ankush Kumar - avatar