+ 1
for i in range(1,5,-1): print("$")
How many times the print statement gets wxwcute
7 Answers
+ 4
The range() method works so that it starts counting at the number given in your first argument, counts to the last number before the number in your second argument, with size steps given in your third.
So when you say range(1,5,-1), you're saying start at 1 and count backwards until just before you reach 5. This is why it doesn't print anything.
If you want to count backwards, you have to reverse the first two numbers in your arguments. So range(5,1,-1) will go 5,4,3,2. range(1,5,-1) will do nothing.
+ 2
0 times
+ 2
It DoEs NoT pRiNt AnYtHiNg.
+ 1
Explain it???
+ 1
It's because -1 is a negative number, so the program knows it will never execute!!!
+ 1
Shreyansh That is not true.
You can give range up to 3 arguments.
- 1
To many parameters (only one is allowed)