0
Why does this code not print 4?
Here’s my code: # Message to be displayed message = "Fasten your seat belt" # for loop to display the message 3 times for i in range(3): print(message) I think I’m just missing something obvious but the counter in the for loop starts at 0 correct? If so it should be 0,1,2,3 which is 4 times the loop should run? Sorry for missing something so simple. Thanks in advance.
4 Réponses
+ 6
You can think the range() function like this: Repeat the action x times.
However, if you assign the start and end values, always remember start value is included, but not the stop value.
Example:
for i in range(3, 10):
print(i)
Only 3, 4, 5, 6, 7, 8 and 9 are printed.
+ 4
Thank you for your comments! I think i understand it better.
Thanks fkr taking the time to hep explain!!
0
I need help on building a landing page
0
Hi