0
How does range work
I want to out put a leaderboard style answer to 9 with a full stop after each number. I tried to use this and just want to check if their is a more efficient way or does this even work: num = 1 for i in range(1, 9): print(num + ‘.’\n) num += 1
4 Antworten
+ 2
You need to change range to one more and edit print like this
print(str(num)+'.\n')
0
You may as well delete the line num += 1. Each time through the loop, num advances to the next value in the range, overwriting whatever value you might set inside the loop.
0
So should I just use i in place of num?
0
I need to correct myself. I was thinking num was the loop index, like this
for num in range(1, 9):
So, yes, you may use the above loop, or use i instead of num in the print statement.