You can use the for
for this, I will put an example below.
for count in range(10, -1, -1):
print("Eu conto", count)
is quite simple
in addition you can add the team, I will give an example below
import time
for count in range(10, -1, -1):
print("Eu conto", count)
time.sleep(1)
doing so wait 1 second each time you count a number
and another way down to a line would be like this
print(*[f'Eu conto {count}' for count in range(10, -1, -1)], sep='\n')
then just choose the one that suits you best and make your modifications
Explaining the issue of range for better understanding
range te a generating function that iterates according to past variables, which can only be stop, for example range(10)
account from 0 to 9, remembering that it does not go to the end, or we can inform the numbers that will start (start), stop (stop) and when numbers it jumps, for example range(2, 20, 5)
he will start counting from number 2 and finish at number 20, but he will jump from 5 to 5 giving you a result equal to [2, 7, 12, 17]
I hope you were able to explain a little.
The comparison operator is the
==
, the operator=
is the allocation operator. Use:if count == 0:
.– anonimo
Ah, it’s true, thank you!
– punksn0g
It is also not necessary to inform that the number 10 is of type int because Python already knows. If you want you can remove it.
– JeanExtreme002
I figured I wouldn’t have to, but I was making a mistake so I put.
– punksn0g
Why did you use the int() function if the numbers are already integers?
– Guilherme Nascimento
Why not put the comparison on
while
? Would remove theif
and thebreak
within it– Costamilam
It’s just that I was trying to find a function that did the checking only after the code execution.
– punksn0g