'Adding a print out message to count in loop (Python)
With 'range' is it possible to add a print out message when the count hits a number in the range:
Starting with this:
for number in range(0,11):
print(number)
Solution 1:[1]
for number in range(0, 11):
if number == 6: #the number in the range
print(f'Number has hit {number}')
Solution 2:[2]
Turn that question into pseudocode. Let's say 7 is your target number.
for number in range between 0,11
if number equals my target number
print out that number
With that rational, it might be something like this:
for number in range(0,11):
if(number == 7):
print("here is the target number: ", number)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user |
| Solution 2 | Gusta |
