Skip to main content
added 4 characters in body
Source Link
Billal Begueradj
  • 3.4k
  • 10
  • 25
  • 34

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.

Code explanation:

count_down -= 1 is equivalent to count_down = count_down - 1. You can read more on Python basic operators.

You do not need to check within the while loop if count_down reached the 0 value because it is already done when you coded while (countDown>=0). I mean you are duplicating the checking. In order to keep DRY, I just decrement the value of count_downcount_down by 1 and the breakbreak instruction is done by default as I am testing while(count_down) meaning if count_down != 0 in this context (because it also means while count_down is not False or None).

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.

Code explanation:

count_down -= 1 is equivalent to count_down = count_down - 1. You can read more on Python basic operators.

You do not need to check within the while loop if count_down reached the 0 value because it is already done when you coded while (countDown>=0). I mean you are duplicating the checking. In order to keep DRY, I just decrement the value of count_down by 1 and the break instruction is done by default as I am testing while(count_down) meaning if count_down != 0 in this context (because it also means while count_down is not False or None).

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.

Code explanation:

count_down -= 1 is equivalent to count_down = count_down - 1. You can read more on Python basic operators.

You do not need to check within the while loop if count_down reached the 0 value because it is already done when you coded while (countDown>=0). I mean you are duplicating the checking. In order to keep DRY, I just decrement the value of count_down by 1 and the break instruction is done by default as I am testing while(count_down) meaning if count_down != 0 in this context (because it also means while count_down is not False or None).

added 672 characters in body
Source Link
Billal Begueradj
  • 3.4k
  • 10
  • 25
  • 34

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.

Code explanation:

count_down -= 1 is equivalent to count_down = count_down - 1. You can read more on Python basic operators.

You do not need to check within the while loop if count_down reached the 0 value because it is already done when you coded while (countDown>=0). I mean you are duplicating the checking. In order to keep DRY, I just decrement the value of count_down by 1 and the break instruction is done by default as I am testing while(count_down) meaning if count_down != 0 in this context (because it also means while count_down is not False or None).

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.

Code explanation:

count_down -= 1 is equivalent to count_down = count_down - 1. You can read more on Python basic operators.

You do not need to check within the while loop if count_down reached the 0 value because it is already done when you coded while (countDown>=0). I mean you are duplicating the checking. In order to keep DRY, I just decrement the value of count_down by 1 and the break instruction is done by default as I am testing while(count_down) meaning if count_down != 0 in this context (because it also means while count_down is not False or None).

Source Link
Billal Begueradj
  • 3.4k
  • 10
  • 25
  • 34

You can get rid of some instructions by writing this instead:

count_down = 3
while (count_down):
   print(count_down)
   count_down -=  1
print('Action!')

Note that I have replaced countDown by count_down to comply with PEP8' naming conventions.