+ 1

for i in range(1,5,-1): print("$")

How many times the print statement gets wxwcute

23rd Jun 2019, 8:12 AM
Hari Hara Suthan.S
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.
23rd Jun 2019, 8:36 AM
Russ
Russ - avatar
+ 2
0 times
23rd Jun 2019, 8:18 AM
Airree
Airree - avatar
+ 2
It DoEs NoT pRiNt AnYtHiNg.
23rd Jun 2019, 8:21 AM
Seb TheS
Seb TheS - avatar
+ 1
Explain it???
23rd Jun 2019, 8:20 AM
Hari Hara Suthan.S
+ 1
It's because -1 is a negative number, so the program knows it will never execute!!!
23rd Jun 2019, 8:21 AM
Airree
Airree - avatar
+ 1
Shreyansh That is not true. You can give range up to 3 arguments.
23rd Jun 2019, 1:33 PM
Seb TheS
Seb TheS - avatar
- 1
To many parameters (only one is allowed)
23rd Jun 2019, 11:56 AM
Shreyansh